-
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
-
Ok so.. set it to true at the beginning of every loop.
-
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
Forum Rules
|
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
|
Bookmarks