title: How to stop exception when type in wrong data type using scanner
body: <p>Can someone tell me how to prevent this:</p>
  
  <p><code>"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.nextInt(Scanner.java:2160)
      at java.util.Scanner.nextInt(Scanner.java:2119)
      at JeffSky.main(JeffSky.java:25)"
  </code>
  when the user inputs a letter for an int. </p>
  
  <p>Basically I am trying to find out how to keep the program running even though a wrong data type has been entered. Just like you can do an if statement to notify the user it is not allowed if they input an int outside a given range e.g from 1-10.</p>
  
  <p>for(int x=1; x&lt;=3;x++) {</p>
  
  <pre><code>int guess;
          System.out.print("Your chosen trap is: "); 
  
          do{
              guess=sean.nextInt();
  
              if(guess&gt;=1 &amp;&amp; guess&lt;=6){   
                  //do nothing if is a valid number i.e a trap between 1 and 6.
              }                                           
              else {
                  System.out.print("Has to be between 1-6. Try again: ");
              }
          }
  
          while(guess&lt;1 || guess&gt;6);
  </code></pre>
  
  <p>Cheers</p>