只是有點困惑,這裏發生了什麼。例如,該錯誤陷阱的重點在於用戶輸入3個數字/字母而不是4位數字。這個錯誤陷阱的設計循環直到用戶正確的問題。但是它會循環顯示錯誤消息。任何人都可以提供一些關於發生什麼的指針?錯誤捕獲幫助;消息不斷重複
JFrame Error = new JFrame();
String input = JOptionPane.showInputDialog(null,"Enter the 4 digit resistor values:");
while (true){
try{
int numInput = Integer.parseInt (input);
if (numInput >= 1000) {
break;
}
else {
JOptionPane.showMessageDialog(Error,"Invalid Input.");
}
}
catch (Exception e){
JOptionPane.showMessageDialog(Error,"Invalid Input.");
}
}
要求輸入的行不在循環中。 – 2013-04-07 03:12:59