Extended GCD final iteration
<p>I'm trying to set up a table showing the values of an extended gcd. I'm getting the values I need until that last iteration of the quotient array. For the final line, I want the firstNumber to show the remainder as 1, but it keeps showing the value as 0. Here is my program: </p>

<pre><code>import java.util.Scanner;

public class GCD {

public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    //Get input numbers
    System.out.println("Enter a number: ");
    int firstNum = in.nextInt();

    System.out.println("Enter another number: ");
    int secondNum = in.nextInt();

    //Calculate quotients and remainders and put them into arrays
    int a = firstNum;
    int b = secondNum;
    int q = 0;
    int r = 0;
    int count = 0;
    int[] quotient = new int[20];
    int[] firstNumber = new int[20];
    int[] secondNumber = new int[20];
    do{
            firstNumber[count] = a;
            secondNumber[count] = b;
            q = a/b;
            r = a%b;
            a = b;
            b = r;
            quotient[count] = q;

            count++;
    } while (b != 0);

     //Find the x and y values for each iteration
    int[] x = new int[20];
    int[] y = new int[20];
    x[0] = 1;
    x[1] = 0;
    y[0] = 0;
    y[1] = 1;

        //X values
        for (int i = 2; i &lt; count+1; i++){
            x[i] = x[i-2] - quotient[i-2]*x[i-1];
        }
        //Y values
        for (int j = 2; j &lt; count+1; j++){
            y[j] = y[j-2] - quotient[j-2]*y[j-1];
        }   

        System.out.println("");
        System.out.println("");

        //Extended GCD Table
        System.out.println("Extended GCD(" + firstNum + ","+ secondNum + ")");
        for (int m = 0; m &lt; count+1; m++){
            System.out.println(firstNumber[m] + " r[" + m + "]: " +        secondNumber[m] + " x[" + m + "]: " + x[m] + " y[" + m + "]: " + y[m]);
        }
        System.out.println("(" + firstNumber[count] + "," + x[count] + "," +     y[count] + ")");

}
</code></pre>

<p>}</p>

<p>And here is my output: </p>

<pre><code>Enter a number: 
89

Enter another number: 
57



Extended GCD(89,57)

89 r[0]: 57 x[0]: 1 y[0]: 0

57 r[1]: 32 x[1]: 0 y[1]: 1

32 r[2]: 25 x[2]: 1 y[2]: -1

25 r[3]: 7 x[3]: -1 y[3]: 2

7 r[4]: 4 x[4]: 2 y[4]: -3

4 r[5]: 3 x[5]: -7 y[5]: 11

3 r[6]: 1 x[6]: 9 y[6]: -14

0 r[7]: 0 x[7]: -16 y[7]: 25

(0,-16,25)
</code></pre>

<p>For the last line of the table, I want it to show</p>

<pre><code>1 r[7]: 0 x[7]: -16 y[7]: 25
</code></pre>

<p>so that the extended gcd solution is (1,-16,25) instead of (0,-16,25). Why isn't the 1 from the line previous (3 r[6]: 1 x[6]: 9 y[6]: -14) carrying down to the final line?</p>
