I've got a very simple problem (i'm starting Java), but for some reason, I cannot find a decent answer. I'm making a program, and the user has to make a choice and an input. But I need to do some checking for valid input, and if he inputs a char
instead of an int
, I need to give him an error message.
The code is:
Scanner n = new Scanner (System.in);
System.out.print("...");
sp = n.nextInt();
if ( sp != 1 )
{
if ( sp == 2 )
{
System.out.println("...");
}
}
else
System.out.println("...");
**//and here the error message shoub be,**
**//in case the user inputs something different than a int**