2017-10-10 1 views
-2

예를 들어 사용자가 내 프로그램에 속하지 않은 내용을 입력 할 때 "거부 됨"일만 필요하지만 많은 "거부 됨"이 결과에 계속 나타나면 감사합니다.누군가가이 문제를 해결할 수 있습니다.

가져 오기 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"); 



    } 
    } 
    } 
+0

내가주는 시도를 모든 경우에 진술 거부 말한다 다른 문을 해당하지만 난 예를 들어 문자를 입력 "S"가 거부 5 – chocomoofy

+0

귀하의 질문을 계속 나타나는 경우 충분히 명확하지 않습니다. 그것을 분명히하십시오? –

+0

'if' 대신 하나의 명령문 만 실행되도록하려면'if' 대신'else if'를 사용하십시오. – 4castle

답변

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 
} 
+0

감사합니다 : D – chocomoofy

관련 문제