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의 문 오류가 아닙니다. (다른 줄뿐만 아니라 문자열을 만들 때)
** 1) ** continue는 예약어이므로 해당 이름의 변수를 사용할 수 있습니다. [계속 키워드 란 무엇이며 어떻게 Java에서 작동합니까?] (https : // stackoverflow .com/questions/389741/what-is-the-continue-keyword-and-how-in-work-in-java) ** 2) ** while (조건) ;' – AxelH
'continue'는 자바의 키워드입니다. 변수 이름으로 사용할 수 없습니다! – alfasin
많은 오류가 있습니다 ... – m0skit0