Here is the javadoc for Scanner
. Scanner is an API to parse input data but it's up to the programmer to tell the code inside the loop what to do.
There isn't anything in the javadoc about Control-Z causing it to break out of a loop. I don't know why you think that it would work that way.
Depending on how you started the program, it is possible to kill the entire program at any time by pressing Control-C (from a DOS window). But, that is just a command in DOS that kills the running program. It has nothing to do with any Java class or methods.