Answer in the API : nextInt(): An invocation of this method of the form nextInt() behaves in exactly the same way as the invocation nextInt(radix)
nextInt(radix): This method will throw InputMismatchException if the next token cannot be translated into a valid int value as described below. If the translation is successful, the scanner advances past the input that matched
So you'll have to advance past the incorrect input if you want to continue scanning for an int.
Joined: Feb 28, 2007
If the translation is successful, the scanner advances past the input that matched.
It means scan.nextInt(); fails to translate what is given to it, "a" will consist the previous value, just before succeeded input. That is correct as I did so.
But how can be corelate this thing with what happened with my code? and when I use nextLine() in the catch clause why doesn't it ask for input. It means if previous nextInt() fails to translate, the further nextLine() will only advance automatically, without asking input.???