System.out.println("How long is the word you would like to guess?");
while (goodInput==false)
{
try
{
wordSize=scan.nextInt();
goodInput=true;
}
catch(InputMismatchException ime)
{
System.out.println("Thats not a number! Try again");
}
}
The console repeats the “Thats not a number…” in infinite loop after the wrong type of input is entered.
*edit
I tried
while(goodInput==false)
{
if (scan.hasNextInt())
{
wordSize=scan.nextInt();
goodInput=true;
}
else
{
System.out.println("Thats not a number! Try again");
}
}
which also produces same error
You never consume the input if a non-integer is supplied, so the input is passed through again and again resulting in an infinite loop. You could use:
in your exception block but better to use: