title: Scanner input - end of input stream indicator
body: <p>I want to do the following : Read numbers into a stack; 
  Read out numbers from stack one by one; 
  Find square root for each number and print result</p>
  
  <pre><code>//need a stack class 
  import java.util.Iterator;
  import java.util.Stack;
  import java.io.*;
  import java.util.*;
  import java.lang.Math;
  
  
  public class Root { 
      public static void main (String[] args) {
  
          Scanner inscan  = new Scanner(System.in);
          PrintWriter out = new PrintWriter(System.out);
  
          Stack&lt;Integer&gt; stk = new Stack&lt;Integer&gt;(); 
          //Iterator iterate = stk.iterator();
  
          //Read the input stream and push them onto the stack
          while ( (inscan.hasNext()) ){                        //LOOP1
              stk.push(inscan.nextInt());     
          }
          //Pop contents of stack one by one and find square root 
          while ( ! stk.isEmpty() ) {
              int num = stk.pop();
              double root = Math.sqrt(num);
              out.printf("%.4f\n",root);
          }
          inscan.close();
          out.flush();
  
      }
  }
  </code></pre>
  
  <p>The problem is with reading inputs (<strong>inscan.hasNext()</strong> ). 
  After entering the last number on the console, program still expects me to supply input - keeps waiting. </p>
  
  <p>How do I let the program know Im done entering input/ should I change LOOP1 above? </p>