This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes invalid input Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply 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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: invalid input
 
Similar Threads
IO
Invalid input integer.
Setting the classpath
Sorting vectors... a nightmare?
Comments on my first program to use an object