title: Reading standard input via command line java
body: <p>I am taking a course Algorithms 1 by Sedgwick (Princeton University) and trying to read an integer from standard input which represents the number of integer pairs that will be input , then a list of integer pairs from standard input.</p>
  
  <p>For example:</p>
  
  <pre><code>3                     //first integer represents number of pairs
  
  12  34                  //list of integer pairs
  
  23  56
  
  34  78
  </code></pre>
  
  <p>I was hoping to type:</p>
  
  <pre><code>java  myProg   3  12   34  23  56   34  78  
  </code></pre>
  
  <p>at the command prompt in windows command line and read first the 3, then in a loop and process each pair in turn.</p>
  
  <p>The code given in the video is this: </p>
  
  <pre><code>package getArgs;
  
  public class getInput {
  
  public static void main(String[] args) {
      int N = StdIn.readInt();   //read first integer 
      while (!Stdin.isEmpty()){  // loop through pairs
          int p = StdIn.readInt();
          int q = StdIn.readInt();
          //process p and q      //process each pair
  
      }
  
  
  }
  </code></pre>
  
  <p><em>Question:</em></p>
  
  <ol>
  <li><p>In the code is Stdin.readInt() actual java or pseudocode?</p></li>
  <li><p>If it is not pseudocode do I need to import a library to access StdIn?</p></li>
  <li><p>If it is pseudocode do I use a Scanner class to replace StdIn.readInt()?</p></li>
  </ol>
  
  <p>The rest of the program works , that is the union find class algorithm, this driver to test the program was not explained well and confused me a little.</p>
  
  <p>Here is my revised attempt - it is ugly</p>
  
  <pre><code>public class getInput {
  
  
  
  public static void main(String[] args) {
  
      int i = 0;  //counter;
      int N = 0;  
  
  
      N = Integer.parseInt(args[0]);  //Read first Integer 
      System.out.println(N );         //check it works
      i = i + 1;
  
      while ( i &lt; N * 2 ){
  
          int p = Integer.parseInt(args[i]);  //get first of the next pair
          i=i + 1;
          int q = Integer.parseInt(args[i]);  //get second of the next pair
          System.out.println(p + "  " + q );  //check
  
  
      }
  
  
  }
  </code></pre>
  
  <p>This works but is uglier than the StdIn - can anyone rewrite it using StdIn so that java recognizes StdIn?</p>