2015-10-17 32 views

回答

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(); 
    } 
} 

Source