Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

invalid input

 
ashley sands
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
ashley sands
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Ashley,

Just look at the Javadocs of the Integer class.

Herman
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic