Results 1 to 2 of 2
- 09-28-2010, 10:07 PM #1Member
- Join Date
- Sep 2010
- Rep Power
Getting show dialog box to generate properly
Hi, I have a feeling I'm gonna feel pretty dumb when someone helps me with this. I'm really really new and am probably over my head with this stuff but my determination to learn is relentless. I have get the user to type in their phone number in the dialog box and show their number in this format nnn nnn nnnn with spaces but i should assume whenever they type it in that it will be written like so: nnn-nnn-nnnn. Everytime I try I get thrown this exception
Exception in thread "main" java.lang.NumberFormatException: For input string: "nnn-nnn-nnnn"
at sun.misc.FloatingDecimal.readJavaFormatString(Floa tingDecimal.java:1224)
at Chapter3Question66.main(Chapter3Question66.java:16 )
any help would be greatly appreciated.
p.s. here is a copy of what i've written:
/* Chapter 3 Question 66
* V. H.
public class Chapter3Question66
public static void main( String  args)
String input = JOptionPane.showInputDialog( null, "Please enter your telephone number" );
Double number = Double.parseDouble( input );
JOptionPane.showMessageDialog( null, " Your telephone number is " + number );
- 09-28-2010, 10:26 PM #2
Read the API doc for the method: parseDouble()
What kind of data will it accept without a problem?
What kind of Exceptions does it throw if the input is wrong?
You need to use another technique to parse the input String to extract the data in the format you want it in.
What formats can the user enter the input in?
For each one you need to write specific code to extract the data you want.
- By akritc in forum AWT / SwingReplies: 7Last Post: 06-10-2010, 02:49 PM
- By Basit781 in forum CLDC and MIDPReplies: 3Last Post: 05-27-2010, 10:54 AM
- By java_bond in forum New To JavaReplies: 0Last Post: 03-05-2010, 05:21 AM
- By mostafa in forum EclipseReplies: 0Last Post: 11-22-2008, 12:47 PM
- By fahimaamir in forum NetBeansReplies: 1Last Post: 01-26-2008, 07:20 AM