谁能纠正这个dfa java

时间:2017-10-10 01:48:53

标签: 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");



    }
    }
    }

1 个答案:

答案 0 :(得分:0)

是否一直无限地输出“被拒绝”?另外,使用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
}