不知道如何實現不匹配例外。當它應該是一個int並且沒有程序崩潰時,如何鍵入一個字母?不匹配例外問題
try {
System.out.print("Enter graduation year : ");
year = response.nextInt();
} catch (InputMismatchException ex) {
while (year < 1920 || year > 2010) {
System.out.print("invalid value. Enter a year between 1920 and 2010 : ");
year = response.nextInt();
}
真棒感謝。 – user3344218
@ user3344218:不客氣! –
@ user3344218:查看編輯 –