title: Using java scanner to check two conditions while taking user input
body: <p>I need to user to enter an int between 1 and 301.
  I have this simple loop here to check for user input.
  I just want a single number from the user, and if the user enters <em>anything</em> other than an int between 1 and 301, I want to display the print line and prompt the users to try again until they enter a valid input. </p>
  
  <pre><code>        while (!sc.hasNextInt()) {
              System.out.print("Invalid Input. Please enter a valid number between 1 and 301: ");
              sc.next();
          }
          int numToCheck = sc.nextInt();
          // do stuff with numToCheck
  </code></pre>
  
  <p>This checks that the input is an int, but I can't seem to find a way to give the int input a bound. I tried to assign the user input to a variable and then check the conditions input &lt; 1 or input > 301, but I get InputMismatchException if user enters a letter. How should I store the user input? (I want to store it as an int to check the conditions, but can't do that since I don't know what the user will enter). </p>
  
  <p>Perhaps there is a better design to accomplish all this. Those are welcomed too.</p>
  
  <p>Thanks in advance.</p>