JAVA
java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
Pascal's Triangle is a triangular array of numbers in which those numbers at the ends of the rows are 1 and each of the others is the sum of the nearest two numbers in the row above.
For Example: A trinagle with an input of 4 would look like this
1
1 1
1 2 1
1 3 3 1
*/
import java.util.InputMismatchException;
import java.util.Scanner;
public class Pascal {
public static void printAsTriangle (int[][] arr) {
int n = arr.length;
for (int i = 0; i < n; ++i) {
for(int j = 0; j < n -1 - i; ++j){
System.out.print("\t");
}
for (int j = 0; j < arr[i].length; ++j) {
System.out.print(arr[i][j] + "\t\t");
}
System.out.println();
}
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run