title: How to handle InputMismatchException?
body: <p>Here is an example from Bruce Eckel Thinking in Java, 4th edition</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.StringReader;
  import java.util.Scanner;
  
  public class BetterRead {
    public static void main(String[] args) {
      BufferedReader input = new BufferedReader(new StringReader("Sir Robin of Camelot\n22 1.61803"));
      Scanner stdin = new Scanner(input);
      System.out.println("What is your name?");
      String name = stdin.nextLine();
      System.out.println(name);
      System.out.println("How old are you? What is your favorite double?");
      System.out.println("(input: &lt;age&gt; &lt;double&gt;)");
      int age = stdin.nextInt();
      double favorite = stdin.nextDouble();
      System.out.println(age);
      System.out.println(favorite);
      System.out.format("Hi %s.\n", name);
      System.out.format("In 5 years you will be %d.\n",
        age + 5);
      System.out.format("My favorite double is %f.",
        favorite / 2);
    }
  }
  </code></pre>
  
  <p>here is output</p>
  
  <pre><code> What is your name?
  Sir Robin of Camelot
  How old are you? What is your favorite double?
  (input: &lt;age&gt; &lt;double&gt;)
  Exception in thread "main" java.util.InputMismatchException
      at java.util.Scanner.throwFor(Scanner.java:909)
      at java.util.Scanner.next(Scanner.java:1530)
      at java.util.Scanner.nextFloat(Scanner.java:2388)
      at betterread.BetterRead.main(BetterRead.java:21)
  Java Result: 1
  </code></pre>
  
  <p>I'm pretty new to Java, but as you can see in this example int follows buy double. So it might work right. But still throws InputMismatchException. How to solve this problem?</p>