Variable value different outside of if statement : <p>In this block of code, at line thirteen, I incremented correctAnswers by 1. However, once the if statement has broke, The value is just one (or zero sometimes) when it prints the percentage. Can anyone tell me what is wrong with my code?</p>

<pre><code>private static void multiplicationTest(int maxNumber, int minNumber) {  
    int i = 1;                                                          

    while(i != 11) {                                                    
        int firstNumber = (minNumber + (int)(Math.random() * ((maxNumber - minNumber) + 1)) ), secondNumber = (minNumber + (int)(Math.random() * ((maxNumber - minNumber) + 1)) );
        int inputAnswer, answer = (firstNumber * secondNumber);
        int correctAnswers = 0;

        System.out.print("Question " + i + ".)\t" + firstNumber + " * " + secondNumber + " = ");
        inputAnswer = input.nextInt();

        if(inputAnswer == answer) {
            correctAnswers++;
            System.out.print("\tcorrect\n");

        } else {
            System.out.print("\tincorrect --- " + firstNumber + " * " + secondNumber + " = " + answer + "\n");

        } if(i == 10) {
            System.out.println("\nYou scored " + correctAnswers + " out of 10 - " + (correctAnswers * 10) + "%.");

        }

        i++;
    }

}
</code></pre>
