go to previous page   go to home page   go to next page highlighting
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.)


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. A token i a group of characters delimited (surrounded) by one or more spaces.

The token can be any group of contiguous characters, not necessarily characters that can be converted into a numeric data type.


QUESTION 9:

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


go to previous page   go to home page   go to next page