你怎么能检查输入是否为双
radius=Double.parseDouble(JOptionPane.showInputDialog("What is the radius of the circle?"));
答案 0 :(得分:0)
Double.parseDouble
, NumberFormatException
将抛出double
。如果您想对其进行操作,请抓住exception
。
可以做到这一点:
public void parse() {
try {
double d = Double.parseDouble(JOptionPane.showInputDialog("What is the radius of the circle?"));
} catch (NumberFormatException nfe) {
//do something with the input here
nfe.printStacktrace();
}
}