这是我到目前为止的代码,我只是尝试通过输入随机字符来测试它,看看我是否得到了正确的 if 语句(也输入了退出)。
但是,在我输入我的输入后什么都没有发生,有什么原因吗?
先感谢您。
public static void main(String[] args) {
//==============================================================================
// Opening Message.
Scanner scan = new Scanner(System.in);
System.out.print("Welcome to the Theatre Booking System. (QUIT to exit)"
+ "\nWould you like to purchase tickets or list available seats?"
+ "(Purchase/List/Help)");
scan.nextLine();
String answer;
answer = scan.nextLine();
int count = 0;
//==============================================================================
// Nested if statement.
// First if statement.
if (answer.equalsIgnoreCase("purchase")) {
// Code for purchase
} else {
if (answer.equalsIgnoreCase("list")) {
// Code for list
} else {
if (answer.equalsIgnoreCase("help")) {
// Code for help
} else {
if (answer.equalsIgnoreCase("quit")) {
System.exit(-1);
} else {
do {
System.out.print("Sorry, incorrect input please enter"
+ " a valid input (Purchase/List/Help or QUIT to exit");
scan.nextLine();
count++;
} while (!answer.equalsIgnoreCase("purchase")
|| !answer.equalsIgnoreCase("list")
|| !answer.equalsIgnoreCase("quit")
|| !answer.equalsIgnoreCase("help"));
}
}
}
}
}
}