previous | start | next

Read input from standard input

The Scanner class has methods hasNext(), hasNextInt(), etc. that return a boolean depending on whether the next input of the indicated type is on the input.

For input from standard input (the keyboard), hasNext must wait for the user to type in some value. So it simply doesn't return until the user does so.

Instead of using the hasNext() method, the programmer can choose a special value (e.g. -1) for the user to enter to mean no more input.

The special value will only indicate the end of input and will not be processed otherwise.

Such a special value is called a "sentinel".



previous | start | next