forked from jimmysingla0399/Java-FOP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpascaltriangle.java
More file actions
30 lines (27 loc) · 798 Bytes
/
pascaltriangle.java
File metadata and controls
30 lines (27 loc) · 798 Bytes
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
29
30
import java.util.*;
public class pascaltriangle {
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
printPascalTriangle(n);
}
private static void printPascalTriangle(int n) {
int c = 0;
StringBuilder str;
for (int i = 1; i <= n; i++) {
str = new StringBuilder();
for (int j = 1; j <= n - i; j++)
str.append(" ");
for (int j = 1; j <= i; j++) {
if (j == 1 || j == i)
c = 1;
else {
c *= i - (j - 1);
c /= j - 1;
}
str.append(c + " ");
}
System.out.println(str);
}
}
}