0
我只是想要得到age
繼續在catch塊
有效int
值從掃描儀獲取信息,但是,當用戶輸入一個字符串,爲什麼我不能再得到一個int?
這裏是我的代碼:
public static void getAge() throws InputMismatchException {
System.out.print("Enter Your age: ");
try {
age = in.nextInt();
} catch (InputMismatchException imme) {
System.out.println("enter correct value for age:");
in.nextInt(); // why this not works?
}
}
Enter Your age: hh
enter correct value for age:
Exception in thread "main" java.util.InputMismatchException
我想請求,直到一個有效的輸入進入輸入有效的int值。