An interesting problem!
What happens is that the scanner tries to translate a non-integer into an integer and realizes that it cannot, so it throws an InputMismatchException. However, he moves past the marker if the transfer was successful.
, , , , nextInt(). dataType true, .
, catch :
catch(Exception JavaInputMismatch){
System.out.println( sc.next() );
System.out.println("Option not available.Try again.");
}
, :
Enter a number: hello
hello
Option not available.Try again.
Enter a number:
. , next() , . nextInt() .
, , , , , ; , "", , - .
, , , , .