go to previous page   go to home page   go to next page
10 12
13 4 6 0
-2
rats

Answer:

Yes.

When the "rats" is encountered, hasNextInt() returns false and the loop (and program) ends gracefully. (The phrase "ends gracefully" is what programmers say when a program ends without a crash accompanied by error messages.)


HasNext Methods

Methods of Scanner
HasNext MethodReading Method
hasNext() next()
hasNextDouble() nextDouble()
hasNextFloat() nextFloat()
hasNextInt() nextInt()
hasNextLine() nextLine()
hasNextLong() nextLong()

There are several hasNext methods and corresponding next methods. Usually your programs will use the methods for int and double.

The hasNext() and next() methods work with tokens which are groups of characters delimited (surrounded) by one or more spaces.


QUESTION 8:

Does hasNext() consume any of the characters from the stream?