Wednesday, 7 August 2013

How to check if user input is not an int value

How to check if user input is not an int value

I need to check if a user input value is not an int value. I'm rather a
beginner still and I've tried different combinations of what I know so far
but I either get nothing or random errors
For example:
If the user inputs "adfadf 1324" it'll raise a warning message.
So, I have a value:
if(scan.hasNextInt() {
usrInput = scan.nextInt()
validInput = true;
if(validInput != true) {
System.out.print("Invalid Input");
}
}
Is it possible to do something like:
if(usrInput < 1 && (!(nextInt()) {
...
}
I also tried the second one but couldn't get the IDE to accept it.
Probably because the syntax is wrong.

No comments:

Post a Comment