lundi 24 février 2020

Java double parameter recursion

Trying to better understand the double parameter in this recursion question. Any help is appreciated. Just a little lost on how to apply it to other programs ie pascalValue(i, j)

   public static int pascalValue(int i, int j) {
    if (j == 0) {
        return 1;
    } else if (j == i) {
        return 1;
    } else {
        return pascalValue(i - 1, j - 1) + pascalValue(i - 1, j);
    }
}

public static void computeRow(int n) {
    int counter;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= i; j++) {
            System.out.print(pascalValue(i, j) + " ");
        }
        System.out.println();
    }
}

Aucun commentaire:

Enregistrer un commentaire