title: Validating input with while loop and scanner
body: <p>What's the best way about getting a valid integer from a user that is in a specified range <strong>(0,20)</strong> and is an <code>int</code>. If they enter an invalid integer print out error. </p>
  
  <p>I am thinking something like:</p>
  
  <pre><code> int choice = -1;
   while(!scanner.hasNextInt() || choice &lt; 0 || choice &gt; 20) {
         System.out.println("Error");
         scanner.next(); //clear the buffer
   }
   choice = scanner.nextInt();
  </code></pre>
  
  <p>Is this correct or is there a better way?</p>