问题遇到的现象和发生背景
Age:
Exception in thread "main" java.lang.RuntimeException: java.lang.NumberFormatException: For input string: ""
at HRAssistant.createNewApplication(HRAssistant.java:145)
用代码块功能插入代码,请勿粘贴截图
System.out.print("Age: ");
int age= Integer.parseInt(keyboard.nextLine());
String ageString=age+"";
while (!(age > 18 && age < 100)){
System.out.print("Ooops! A valid age between 18 and 100 must be provided: ");
age= Integer.parseInt(keyboard.nextLine());
}
我的解答思路和尝试过的方法
System.out.print("Age: ");
int age= Integer.parseInt(keyboard.nextLine());
String ageString=age+"";
while (!(age > 18 && age < 100)||ageString.isEmpty()){
System.out.print("Ooops! A valid age between 18 and 100 must be provided: ");
age= Integer.parseInt(keyboard.nextLine());
}
我想要达到的结果
希望输入是empty时下一行能正常运行