title: java nextInt() try catch repeating output more than once
body: <p>I am writing a program that accepts two ints within the program using <code>nextInt();</code> and have it wrapped in a <code>try catch</code> block to stop bad inputs such as doubles or chars.</p>
  
  <p>When multiple wrong inputs are entered the loop repeats that same number of times. I assume this is because my <code>scan.next()</code> has to loop around enough times to catch the bad inputs w/o error. Is there a way to know this number on the first run through to make a loop to run next in that many times?</p>
  
  <p>In the output the
    <code>if(cont == 'N') System.out.print("\nPlease re-enter\n\t:");</code> will output and mirror the amount of times a mismatched input was written. That is, if I input 3 3.3 it will repeat one extra time, if input s 3.3 2.5 it will repeat three extra times.</p>
  
  <p>I tried putting a loop around <code>scan.next()</code> to default it to ten times, but was overboard and I had to input an extra 8 characters before it started reading again. Maybe a while loop but what would its condition be, I tried <code>while(scan.next() != null){}</code> but that condition never stopped.</p>
  
  <pre><code>//input error checking
  char cont = 'Y';
  do{
    if(cont == 'N')
      System.out.print("\nPlease re-enter\n\t:");
    cont = 'Y';
    /* to stop the accidential typing of things other
     * than integers from being accepted
     */
    try{
      n1 = scan.nextInt();
      n2 = scan.nextInt();
    }catch(Exception e){
      cont = 'N'; //bad input repeat loop
      scan.next();//stops infinite loop by requesting Scanner try again
    }
  } while(cont == 'N');//do loop while told N for continue
  </code></pre>