title: hasNext() - when does it block and why?
body: <p>I'm trying to read commands via a <code>Scanner</code> Object. For checking the Input Syntax I use <code>sc.hasNext()</code> (for the case of missing commands). It did work fine for many cases already, but now I have the case that's described in the JavaAPI as "MAY block and wait for Input".</p>
  
  <p>When does the <code>hasNext()</code> method block and how can I control it? The funny Thing is that it work's perfectly fine with 3 cases before the block. Also the JavaAPI describes <code>hasNext()</code> as the proper method for checking wether there is another Input or not so that the Method <code>next()</code> doesn't produce an <code>Exception</code>.</p>
  
  <p>Here is the code I did produce till now:</p>
  
  <pre><code>if (sc.hasNext() &amp;&amp; sc.next().equals("create")) {
      if (sc.hasNextInt()) {
          width = sc.nextInt();
          if (width &gt; 0) {
              if (sc.hasNextInt()) {
                  heigth = sc.nextInt();
                  if (heigth &gt; 0) {
                      if (sc.hasNext()) {  //At this point the hasNext Statement blocks for //no reason till an Input is made.
                          charset = sc.next();
                          Image = new AsciiImage(width, heigth,charset);
                      } else {
                          ret = false;
                          System.out.println("INPUT MISMATCH");
                      }
                  } ...//and so on
  </code></pre>
  
  <p>Thanks in advance, I couldn't find anything on this Topic an my own.
  Edit: The Scanner is defined as a System.in, but that shouldn't be a Problem - at least it hasn't been one till now.</p>