我试图做出一个声明,当你输入一个整数终止。我只能使用一个整数继续。我也在考虑试图赶上特定错误女巫是NumberFormatExeption
只是我不够好去弄清楚 这里是我的代码:语句时发生错误
import javax.swing.JOptionPane;
import java.lang.NumberFormatException;
public class Calc_Test {
public static void main(String[] args) throws NumberFormatException{
while(true){
String INT= JOptionPane.showInputDialog("Enter a number here: ");
int Int = Integer.parseInt(INT);
JOptionPane.showConfirmDialog(null, Int);
break;
}
}
}
[编辑] 我清理了我的一些代码,并想出了这在堆栈溢出的朋友的帮助下。下面的代码:
import javax.swing.JOptionPane;
public class Calc_Test {
public static void main(String[] args){
while(true){
String inputInt= JOptionPane.showInputDialog("Enter a number here: ");
if(inputInt.matches("-?\\d+")){
JOptionPane.showConfirmDialog(null, "\"" + inputInt + "\"" + " is a number");
break;
}
JOptionPane.showConfirmDialog(null, "\"" + inputInt + "\"" + " is not a number. Therefore, " + "\"" + inputInt + "\"" + " could not be parsed. Try again.");
}
}
}
继续前进,并得到足够好,这并不难。无论如何,你应该可以抓住它。 – ChiefTwoPencils 2013-05-11 23:00:27
@RexPRGMER:负数有效吗?或数字超过22亿? – jlordo 2013-05-11 23:02:33
任何数字都是我们的目标,但我们想出了它 – RexPRGMER 2013-05-11 23:40:40