Pascal’s triangle is a triangular array of the binomial coefficients.
Program to Display Pascal Triangle in java
class Main
{
public static void pascalTriangle(int n)
{
for (int j = 0; j < n; j++) {
int num = 1;
System.out.printf("%" + (n - j) * 2 + "s", "");
for (int k = 0; k <= j; k++) {
System.out.printf("%4d", num);
num = num * (j - k) / (k + 1);
}
System.out.println();
}
}
public static void main(String[] args)
{
int n=6;
pascalTriangle(n);
}
}
OutPut:-
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1