我無法在這裏定位錯誤:爲什麼我得到「錯誤:'其他'沒有'如果'」?
import java.util.Scanner;
public class StringExample {
public static void main(String[] args) {
Scanner myScanner = new Scanner(System.in);
System.out.println("What's your favorite type of food?");
System.out.println("1. Pizza?");
System.out.println("2. Steak?");
System.out.println("3. Cake?");
String answer = myScanner.next();
if (answer.equals ("Pizza")) {
System.out.println("It's pretty nice, isn't it?");
}else if (answer.equals ("Steak")); {
System.out.println("Yummy :)");
}else if (answer.equals ("Cake")); {
System.out.println("THE CAKE IS A LIE!");
}
}
}
Error: 'else' without 'if'
我得到第17行此錯誤:
}else if (answer.equals ("Cake")); {
分號具有意義。 –
它看起來像這是偉大的複製粘貼技術的副作用:LOL 你有很多分號人 –
你真的沒有接受答案? –