public int testScanner(){
Scanner scanner=new Scanner(System.in);
while (true){
try {
return scanner.nextInt();
}catch (InputMismatchException e){
e.printStackTrace();
}
}
}打算實作一個功能就是讓用戶輸入數字,如果輸入字母就捕捉這個例外重新輸入。
但是實際上并不會重新輸入而是一直彈出例外處理的內容...
求解
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/263993.html
標籤:Java SE
上一篇:正在試驗.不要列印就是錯!
下一篇:C++11 強型別列舉
