title: How to stop reading multiple lines from stdin using Scanner?
body: <p>I'm working on an JAVA assignment should process multiple lines of input. The instructions read "Input is read from stdin."</p>
  
  <p>An example of sample input is given:</p>
  
  <pre><code>one 1
  two 2
  three 3
  </code></pre>
  
  <p>I don't understand what the above sample input "read from stdin" means.</p>
  
  <p>Here's a test program I wrote that isolates my confusion:</p>
  
  <pre><code>import java.io.*;
  import java.util.Scanner;
  
  class Test
  {
  public static void main(String[] args)
  {   
      Scanner stdin = new Scanner(System.in);
      while(stdin.hasNextLine())
      {
          String line = stdin.nextLine();
          String[] tokens = line.split(" ");
          System.out.println(Integer.parseInt(tokens[1]));
      }
  }
  </code></pre>
  
  <p>When I run this program in the console, it waits for my input and each time I input a line it echos it back as I would expect. So I thought perhaps the sample input above would be achieved by entering each of the 3 lines in this fashion. However, there seems to be no way to end the process. After I enter the 3 lines, how do I terminate the input? I tried just pressing enter twice, but that seems to read as a line consisting of only the newline character, which causes an error because the line doesn't fit the 2 token format it expects.</p>
  
  <p>Here's what the console interaction looks like:</p>
  
  <pre><code>javac Test.java
  java Test
  one 1
  1
  two 2
  2
  three 3
  3
  
  Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
      at Test.main(Test.java:13)
  </code></pre>
  
  <p>I'd appreciate any help in pointing out the gap in my understanding.</p>