what does scan.hasnext do
The hasNext() method checks if the Scanner has another token in its input.
A Scanner breaks its input into tokens using a delimiter pattern,
which matches whitespace by default.
That is, hasNext() checks the input and returns true if it has another non-whitespace character.