title: user input check int only
body: <p>I am trying to have my user input not crash my program by restricting what the user can input such as: </p>
  
  <ol>
  <li>only being an int</li>
  <li>being between 1-30</li>
  </ol>
  
  <p>The code that I've written works only up to a certain point. If you enter something thats not an int it will check it and ask you to enter again. Then again if you keep typing anything but an int. I have another while loop if it does type an int, and if it's outside the 1-30 zone then it will ask the user to input again. However after that if the user types another "anything but an int" the program will crash. I've tried to combine both the <code>sc.hasnextint()</code> and the check for input between 1-30 condition but if i put the <code>sc.nextint()</code> before the <code>sc.hasnextint()</code> and the user enters anything but an int, the program crashes. If I put it after the condtion loop, then the userinput will not be declared.</p>
  
  <pre><code>int choose;
  System.out.print("type an integer: ");
  Scanner sc=new Scanner(System.in);
  
  while (!sc.hasNextInt() ) { 
      System.out.println("only integers!: "); 
      sc.next(); // discard 
  } 
  
  choose=sc.nextInt();
  
  while (choose&lt;=0 || choose&gt;30)
  {
      System.out.print("no, 1-30: ");
      choose=sc.nextInt();
  }
  sc.close();
  </code></pre>