2017-11-16 7 views
-1
Scanner reader = new Scanner(System.in); 
    String continue; 
    do { 
     if (eHealth > 0 && pHealth > 0) { 
      if (ranAway != true && stuck = true){ 
       stuck = false; 
       System.out.println("You are now stuck with the monster forever. Good job.\n" 
       + "Would you like to fight again?\n"); 
       continue = reader.nextLine(); 
       if ("Yes".equals(continue) || "yes".equals(continue)){ 
        pHealth = 1500; 
        assignHealth(); 
        Fight(); 
       }else if ("No".equals(continue) || "no".equals(continue)) { 
        System.exit(0); 
       } 
      }else if (ranAway = true && stuck != true) { 
       ranAway = false; 
       System.out.println("You ran away from your problems like the coward you are.\n" 
            + "Do you want to fight again\n"); 
       continue = reader.nextLine(); 
       if ("Yes".equals(continue) || "yes".equals(continue)){ 
        pHealth = 1500; 
        assignHealth(); 
        Fight(); 
       }else if ("No".equals(continue) || "no".equals(continue)) { 
        System.exit(0); 
       } 
      }else { 
       Fight(); 
      } 
     }else if (eHealth > 0 && pHealth <= 0){ 
      System.out.println("Oh noes. You got de_stroyed by the monster! What a shame.\n" 
           + "Would you like to fight again?\n"); 
      continue = reader.nextLine(); 
      if ("Yes".equals(continue) || "yes".equals(continue)){ 
        pHealth = 1500; 
        assignHealth(); 
        Fight(); 
       }else if ("No".equals(continue) || "no".equals(continue)) { 
        System.exit(0); 
       } 
     }else if (eHealth <= 0 && pHealth > 0){ 
      System.out.println("Congrats! You killed the troll!\n" 
           + "Would you like to play again?\n"); 
      continue = reader.nextLine(); 
      if ("Yes".equals(continue) || "yes".equals(continue)){ 
        pHealth = 1500; 
        assignHealth(); 
        Fight(); 
       }else if ("No".equals(continue) || "no".equals(continue)) { 
        System.exit(0); 
       } 
     } 
    } 

이것은 오류를 던지는 부분입니다. 상황은 트롤과의 작은 싸움 일뿐입니다. 다시 시작하는 옵션이 제공됩니다. 일부 항목은 당신이 볼 수있는 부울을 활성화합니다. 오류를주는 주요 줄은 IF 문뿐 아니라 String continue;입니다. 이 문제를 어떻게 해결할 수 있습니까?Java의 문 오류가 아닙니다. (다른 줄뿐만 아니라 문자열을 만들 때)

+3

** 1) ** continue는 예약어이므로 해당 이름의 변수를 사용할 수 있습니다. [계속 키워드 란 무엇이며 어떻게 Java에서 작동합니까?] (https : // stackoverflow .com/questions/389741/what-is-the-continue-keyword-and-how-in-work-in-java) ** 2) ** while (조건) ;' – AxelH

+3

'continue'는 자바의 키워드입니다. 변수 이름으로 사용할 수 없습니다! – alfasin

+0

많은 오류가 있습니다 ... – m0skit0

답변

1
if (ranAway = true && stuck != true) 

이 조건은 ("ranAway = 사실은"할당 실제로) 잘못이며,이 부분에 대한 당신은 단순히 상태는 수

if (ranAway && !stuck) 

당신이 아마 알고, 당신은 "= 사용해야 = "필요한 경우 조건. 많은 코드가 누락되어 문제가 해결되는지 잘 모르겠지만 프로그램에 문제가있을 수 있습니다.

+0

더하기 '계속'은 java, et voilà의 예약 키워드입니다. –