-2
如何检查输入的是双JOptionPane的输入验证。我如何确保输入是双重的?
radius=Double.parseDouble(JOptionPane.showInputDialog("What is the radius of the circle?"));
如何检查输入的是双JOptionPane的输入验证。我如何确保输入是双重的?
radius=Double.parseDouble(JOptionPane.showInputDialog("What is the radius of the circle?"));
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();
}
}