diff --git a/PascalTriangle b/PascalTriangle new file mode 100644 index 0000000..e617999 --- /dev/null +++ b/PascalTriangle @@ -0,0 +1,47 @@ +public class PascalTriangle { + + public static void main(String[] args) { + combination(5); + + } + + public static void Array(int n) { + + int[][] arr = new int[n][n]; + + for (int row = 0; row < arr.length; row++) { + + for (int col = 0; col <= row; col++) { + + if (col == 0 || col == row) { + arr[row][col] = 1; + } else { + arr[row][col] = arr[row - 1][col - 1] + arr[row - 1][col]; + } + + System.out.print(arr[row][col] + " "); + } + + System.out.println(); + + } + } + + public static void combination(int n) { + + for (int row = 0; row < n; row++) { + + int val = 1; + + for (int col = 0; col <= row; col++) { + + System.out.print(val + " "); + val = (val * (row - col)) / (col + 1); + } + System.out.println(); + + } + + } + +}