尝试接受 [0,1,2,3,4] 范围内的用户输入,直到他输入有效数字。使用try-catch修复异常错误
boolean good = true;
int x = reader.nextInt();
while (good != false) {
try {
if (x > launchEventList.size()-1) {
System.out.println("Please provide a valid input");
reader.nextInt();
} else {
System.out.println("\nDetails of event on index "+ x + " are ==>> " + getLe(x));
good = false;
}
}
catch (IndexOutOfBoundsException e) {
System.out.println("Invalid Input");
}
慕工程0101907
相关分类