(bank is a static int variable declared up top)
boolean valid = true;
Scanner scan = new Scanner(System.in);
while (valid) {
try {
System.out.println("How much money do you want to convert to chips?");
bank = scan.nextInt();
valid = false;
} catch(InputMismatchException ex) {
System.out.println("Thats not right try entering a number between 0 and 2,147,483,647");
//bank = scan.nextInt();
continue;
}
}
如果我取消註釋第二個銀行= scan.nextInt();我得到相同的InputMismatchError,但我沒有另一個嘗試捕獲,所以它打印出stacktrace。 我該如何改變這個循環來接受最後一個新的輸入?掃描儀InputMismatchException while循環問題