我正在尝试使用实用程序函数来获取 int 并检查错误的输入是否会导致
NumberFormat 异常,有没有办法为以下函数使用非十进制 Int
//--- Utility function to get int using a dialog.
public static int getInt(String mess) {
int val;
while (true) { // loop until we get a valid int
String s = JOptionPane.showInputDialog(null, mess);
try {
val = Integer.parseInt(s);
break; // exit loop with valid int
} catch (NumberFormatException nx) {
JOptionPane.showMessageDialog(null, "Enter valid integer");
}
}
return val;
}
//end getInt