title: Limit Repeating Addition Quiz- While loop - Java
body: <p>I am trying to code in <code>Java</code> and started with a basic repeating addition quiz. </p>
  
  <p>Repeating addition until enter the correct answer works fine, however, when I try to limit it to 3 trials, it does not stop at 3, but goes for 4 trials as shown below,</p>
  
  <pre><code>import java.util.Scanner;
  
  public class RepeatAdditionQuiz {
  
  public static void main(String[] args) {
      // TODO Auto-generated method stub
      int number1 = (int) (Math.random() * 10);
      int number2 = (int) (Math.random() * 10);
  
      Scanner input = new Scanner(System.in);
      System.out.print("What is " + number1  + " + " + number2 + " : " );
      int answer = input.nextInt();
      int count = 0;
      while(count &lt; 3) {
  
          if (number1 + number2 != answer) {
              System.out.print("Try again, What is " + number1  + " + " + number2 + " : " );
              answer = input.nextInt();
          }
          else
              System.out.println("You're correct ");
  
          count ++;
      }
      System.out.println("Your trails ended ");
  
  }
  
  }
  </code></pre>
  
  <p>This is my output, </p>
  
  <pre><code>What is 1 + 2 : 8
  Try again, What is 1 + 2 : 6
  Try again, What is 1 + 2 : 9
  Try again, What is 1 + 2 : 9
  Your trails ended 
  </code></pre>
  
  <p>As you can see I have four trails with the first one. When I tried to remove first user input before <code>while</code> loop (which prints <code>What is 1 + 2 :</code>), I don't see anything in console. How can I just limit it to 3? </p>
  
  <p>In <code>python</code> I can do something like this,</p>
  
  <pre><code>from random import randint
  
  number1 = randint(0,9)
  number2 = randint(0,9)
  
  answer = number1 + number2
  count = 0
  while count &lt; 3:
      print(number1, "+", number2)
      user_answer = int(input("What is number1  + number2: "))
      if answer == user_answer:
          print("yes, you're right")
          break
      else:
          print("You're wrong, please enter again")
      count +=1
  print("Sorry, all trials are done! ")
  </code></pre>
  
  <p>And I get the output like this, exactly three trails (every time I enter wrong answer),</p>
  
  <pre><code>8 + 5
  What is number1  + number2: 16
  You're wrong, please enter again
  8 + 5
  What is number1  + number2: 18
  You're wrong, please enter again
  8 + 5
  What is number1  + number2: 18
  You're wrong, please enter again
  Sorry, all trials are done! 
  </code></pre>
  
  <p>What mistake am I making in <code>java</code>? Is there any better way to do in <code>while</code> loop? Any suggestion would be appreciated.</p>