title: Java if statement causing method to execute twice
body: <p>I'm trying to make a quiz type game and for some reason when I add the if statement below it executes the ask method twice. You will get asked the question twice before it returns whether it is correct or not.</p>
  
  <pre><code>import java.util.Scanner;
  
  public class QuizGame
  {
  private int correct;
  private int wrong;
  private Scanner inputScan;
  private Quiz customQuiz;
  
  public QuizGame()
  {
     correct=0;
     wrong=0;
     inputScan    =   new Scanner(System.in);
  }
  
  private void startQuiz()
  {
          System.out.println("Use custom upper limit? (y/n) ");
          String custom   =   inputScan.next();
  
          if(custom.equalsIgnoreCase("y"))
          {
              System.out.println("What do you want to be your upper limit?");
              int limit   =   inputScan.nextInt();
              customQuiz  =   new Quiz(limit);
              customQuiz.ask();
  
              if(customQuiz.ask())
              {
                  correct +=1;
                  System.out.println("Correct!");
              }
              else 
              {
                  wrong+=1;
                  System.out.println("Wrong!");
              }
          } 
      }
  
      public static void main(String[] args)
      {
          QuizGame quiz1  =   new QuizGame();
          quiz1.startQuiz();
      }
  }
  </code></pre>
  
  <p>other class that asks the questions:</p>
  
  <pre><code>import java.util.Random;
  import java.util.Scanner;
  
  public class Quiz
  {
      private Random rGen;
      private int num1;
      private int num2;
      private Scanner getInput;
      private int answer;
  
      public Quiz(int n1)
      {
          rGen    =   new Random();
          num1    =   rGen.nextInt(n1);
          num2    =   rGen.nextInt(n1);
          getInput   =   new Scanner(System.in);
  
      }
  
      public boolean ask()
      {
          int answer = num1 * num2;
          System.out.println("What is " + num1 + " x " + num2);
          int userAnswer  =   getInput.nextInt();
  
          return answer == userAnswer;   
      }
  }
  </code></pre>
  
  <p>I isolated the problem and it definitely seems to be the if statement: <code>if(customGame.ask()) {}</code> in the driver class, but I don't see why. It's not like <code>if(customGame.ask())</code> calls the ask method again, it just tests if it returns true? I've also tried with just <code>if(customGame.ask() == true)</code> and still nothing.</p>