title: How do I prevent program from terminating when user inputs a string when the program expects an integer?
body: <p>I'm trying to set up a do-while loop that will re-prompt the user for input until they enter an integer greater than zero. I cannot use try-catch for this; it's just not allowed. Here's what I've got:</p>
  
  <pre><code>Scanner scnr = new Scanner(System.in);
  int num;
  do{
  System.out.println("Enter a number (int): ");
  num = scnr.nextInt();
  } while(num&lt;0 || !scnr.hasNextLine());
  </code></pre>
  
  <p>It'll loop if a negative number is inputted, but if a letter is, the program terminates.</p>