更新时间:2023-11-25 08:55:34
您的条件是否正常,除了您不想两次调用scanner.next()
,这会吃掉"一些输入.
Your if condition is OK, except that you don't want to call scanner.next()
twice, which will 'eat' some input.
您希望将scanner.next()
的值设置为变量,然后在if条件下检查变量值:
You would want to set the value of scanner.next()
to a variable and then check the variable value in the if condition:
String input = scanner.next();
if(input == null || input.equals("")){
//Do something
}