有人可以纠正这个DFA Java吗?

  • 本文关键字:DFA Java java
  • 更新时间 :
  • 英文 :


我的输出,例如,如果用户键入不属于我的程序的内容,则只需 1 个"拒绝",但输出上不断出现许多"拒绝",请帮助谢谢

import java.util.Scanner;公共类 thecomp {

public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    System.out.println("input 0 and 1");
    String a = input.next();
    if (a.equals("01")){
        System.out.println("L1 = {w|w starts with 0 and ends with 1}");
    } 

    if (a.equals("00")) {
        System.out.println("L1 = {w|w starts with 00}");
    } 

    if (a.equals("0")) {
        System.out.println("L1 = {w|w starts with 0}");
    } 

    if (a.equals("0011")) {
        System.out.println("L1 = {w|w ends with 11}");
    } 

    if (a.equals("0011")) {
        System.out.println("L1 = {w|w consists of two 0's and two 1's}");
    } 
      else  {
        System.out.println("REJECTED");

    }
    }
    }

它是否始终无限地输出"拒绝"?此外,使用 switch 语句:

switch(a) {
    case "00":
        System.out.println("It's equal to 00");
        break;
    case "01:
        System.out.println("It's equal to 01");
        break;
    // Continue
}

最新更新