package javaFixer; /** * Program #4 Program To Print Pascal Triangle * @author JavaFixer * */ public class PascalTriangle { public static void main(String[] args) { int n = 5;// No of Rows for (int i = 0; i < n; i++) { for (int j = n - 1; j > i; j--) { System.out.print(" "); } for (int j = 0; j <= i; j++) { System.out.print(getPascal(i, j) + " "); } System.out.println(); } } private static int getPascal(int i, int j) { if (j == 0 || j == i) { return 1; } return getPascal(i - 1, j - 1) + getPascal(i - 1, j); } }
1 1 1 1 2 1 1 3 3 1 1 4 6 4 1