import java.util.Scanner;
public class StudySession {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String inData;
int age;
System.out.println("Enter your age");
while(true) {
inData = in.nextLine();
if(inData == "STOP") {
System.out.println("Terminated");
break;
}
age = Integer.parseInt(inData);
if(age < 5) {
System.out.println("Under 5's rate.");
}
if(age >= 60) {
System.out.println("Senior citizen rate.");
}
if(age <= 17) {
System.out.println("Child rate.");
}
if(age > 17 && age < 65) {
System.out.println("Adult rate.");
}
System.out.println("Enjoy the show!"); //This prints no matter what.
}
}
}
我希望程序在用户键入“STOP”时停止。为什么不起作用?你不必给我一个直接的答案。一条线索就可以了。也许这与我的陈述顺序有关?