I have a small assignment where I have to produce a pascal triangle and then find a number given a user inputted row and column. This is all I have come up with, I do not know how to proceed with calculating the number at a given row and column.
import java.util.Scanner;
public class PascalTriangle {
public static void print(int n) {
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
System.out.print(pascal(i, j) + " ");
}
System.out.println();
}
}
public static int pascal(int i, int j) {
if (j == 0) {
return 1;
} else if (j == i) {
return 1;
} else {
return pascal(i - 1, j - 1) + pascal(i - 1, j);
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the row number");
int row = scanner.nextInt();
print(row);
}
}