title: Java Scanner class reading strings
body: <p>I got the following code:</p>
  
  <pre><code>        int nnames;
      String names[];
  
      System.out.print("How many names are you going to save: ");
      Scanner in = new Scanner(System.in);
      nnames = in.nextInt();
      names = new String[nnames];
  
      for (int i = 0; i &lt; names.length; i++){
          System.out.print("Type a name: ");
          names[i] = in.next();
      }
  
      System.out.println(names[0]);
  </code></pre>
  
  <p>When I run this code, the scanner will only pick up the first name and not the last name. And it will sometimes skip a line when trying to enter a name, it will show up as if I had left the name blank and skip to the next name. I don't know what's causing this.</p>
  
  <p>I hope someone can help me!</p>
  
  <p>EDIT: I have tried in.nextLine(); it fixes the complete names but it still keeps a line, here is an example of the output:</p>
  
  <pre><code>How many names are you going to save:  3
  Type a name: Type a name: John Doe
  Type a name: John Lennon
  </code></pre>