- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPascalsTriangle.java
More file actions
Latest commit
28 lines (21 loc) · 663 Bytes
/
Copy pathPascalsTriangle.java
File metadata and controls
28 lines (21 loc) · 663 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
packagecom.sarvesh.javabasics;
importjava.util.Scanner;
publicclassPascalsTriangle {
publicstaticvoidmain(String[] args) {
Scannerscanner = newScanner(System.in);
System.out.print("Enter number of rows: ");
introws = scanner.nextInt();
for (inti=0;i<rows;i++) {
for (intspace=0;space<rows-i;space++) {
System.out.print(" ");
}
longvalue = 1;
for (intj=0;j<=i;j++) {
System.out.print(value+ " ");
value = value*(i-j)/(j+1);
}
System.out.println();
}
scanner.close();
}
}