0
在下面的代碼中,即使在我給出輸入之前,我仍然在第80行得到了InputMismatchException
。爲什麼是這樣?如何處理這個InputMismatchException?
try {
loop:while(true)
{
choice=sc.nextInt();
switch (choice) {
case 1:
term=3;
break loop;
case 2:
term=6;
break loop;
default:
System.out.println("Invalid Input.. Enter again");
choice=sc.nextInt();
}
}
}
catch (InputMismatchException e2) {
System.out.println("Wrong Format!! Enter a number");
choice=sc.nextInt(); //line 80
}