它在 IF 语句中有效,但在 ELSE 语句中,我必须输入 4 个响应才能打印出来。有任何想法吗?我知道我需要以某种方式清除缓冲区。
System.out.println("Would you like to play a game? (Y/N)");
if(scanInput.next().equalsIgnoreCase("y")||scanInput.next().equalsIgnoreCase("Y")) {
System.out.println("let's play");
}
else if (scanInput.next().equalsIgnoreCase("n") || scanInput.next().equalsIgnoreCase("N")){
System.out.println("Goodbye");
}