numberformatexception


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: numberformatexception

  1. #1
    Join Date
    May 2004
    Posts
    29

    numberformatexception

    try
    {
    num = Integer.parseInt(JOptionPane.showInputDialog("Enter a number"));
    }

    catch(NumberFormatException nfe)
    {
    System.out.println("Sorry. You need to enter a number");
    }

    if user enters a number, all goes well. if not, that statement will b printed. now, this happens only once. i want it to happen repeatedly. so i thought of including a do while loop but it didnt work. it kept repeatedly asking me to enter a number. here's the code:-

    do
    {
    try
    {
    num = Integer.parseInt(JOptionPane.showInputDialog("Enter a number"));
    }

    catch(NumberFormatException nfe)
    {
    System.out.println("Sorry. You need to enter a number");
    flag = false;
    }
    }
    while(!flag);

    if i removed the !, it still wont work. i believe it works only the first time. but then since flag becomes false, it'll keep asking me no matter what i enter.
    help plz
    thanx

  2. #2
    Join Date
    May 2004
    Posts
    219
    Ok so.. set it to true at the beginning of every loop.

  3. #3
    Join Date
    May 2004
    Posts
    29
    it worked!!!
    thanx a lot man!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center