DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  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!

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links