title: Using Scanner.next() to get text input
body: <p>I am trying to get text input from the keyboard in Java 6.  I am new to the language and whenever i run the following code, I get this error:</p>
  
  <pre><code>package test1;
  import java.util.Scanner;
  public class Test {
  public static void main(String[] args) {
      boolean quit = false;
      while (!quit){
          Scanner keyIn;
          String c = "x";
          while (c != "y" &amp;&amp; c != "n") {
              keyIn = new Scanner(System.in);
              c = keyIn.next();
              keyIn.close();
          }
          if (c == "n")
              quit = true;
      }
   }
  }
  
  
  Exception in thread "main" java.util.NoSuchElementException
  at java.util.Scanner.throwFor(Scanner.java:838)
  at java.util.Scanner.next(Scanner.java:1347)
  at test1.Test.main(Test.java:11)
  </code></pre>
  
  <p>Am I mis-using the next() method?  I thought it would wait for user input but it looks like it isn't and throwing the exception saying that there is nothing left in the scanner.</p>