title: How to read strings from a Scanner in a Java console application?
body: <pre><code>import java.util.Scanner;
  class MyClass
  {
      public static void main(String args[])
      {
          Scanner scanner = new Scanner(System.in);
          int employeeId, supervisorId;
          String name;
          System.out.println("Enter employee ID:");
          employeeId = scanner.nextInt();
          System.out.println("Enter employee name:");
          name = scanner.next();
          System.out.println("Enter supervisor ID:");
          supervisorId = scanner.nextInt();
      }
  }
  </code></pre>
  
  <p>I got this exception while trying to enter a first name and last name.</p>
  
  <pre><code>Enter employee ID:
  101
  Enter employee name:
  firstname lastname
  Enter supervisor ID:
  Exception in thread "main" java.util.InputMismatchException
      at java.util.Scanner.throwFor(Unknown Source)
      at java.util.Scanner.next(Unknown Source)
      at java.util.Scanner.nextInt(Unknown Source)
      at java.util.Scanner.nextInt(Unknown Source)
      at com.controller.Menu.&lt;init&gt;(Menu.java:61)
      at com.tests.Employeetest.main(Employeetest.java:17)
  </code></pre>
  
  <p>but its working on if I only enter the first name.</p>
  
  <pre><code>Enter employee ID:
  105
  Enter employee name:
  name
  Enter supervisor ID:
  501
  </code></pre>
  
  <p>What I want is to read the full string whether it is given as <code>name</code> or as <code>firstname lastname</code>. What's the problem here?</p>