aspose file tools*
The moose likes Beginning Java and the fly likes invalid input Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "invalid input" Watch "invalid input" New topic
Author

invalid input

ashley sands
Greenhorn

Joined: Feb 22, 2007
Posts: 2
in my program, i want the user to enter an integer. if they enter a double or character, i don't want the program to crash. i want it to go into a while loop that keeps running until they enter an integer.
i have no idea how to get the program to keep running when the input is invalid... can someone help?
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by ashley sands:
...i want it to go into a while loop that keeps running until they enter an integer. i have no idea how to get the program to keep running when the input is invalid...

Welcome to JavaRanch!

It sounds like you do have an idea: "go into a while loop that keeps running until they enter an integer." That suggests something like this...

So the questions are how do you get the input and how do you test the input to see if it's an int? What have you tried so far?
[ February 22, 2007: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
ashley sands
Greenhorn

Joined: Feb 22, 2007
Posts: 2
i know how to get input and form the while loop and all of that, i just don't know how to test if it's an integer...
Herman Schelti
Ranch Hand

Joined: Jul 17, 2006
Posts: 387
hi Ashley,

Just look at the Javadocs of the Integer class.

Herman
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: invalid input