-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPascalTriangle.java
More file actions
34 lines (27 loc) · 791 Bytes
/
Copy pathPascalTriangle.java
File metadata and controls
34 lines (27 loc) · 791 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
31
32
33
34
import java.util.*;
class PascalTriangle {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of lines : ");
int lines = input.nextInt();
for(int i = 0; i < lines; i++){
for(int j = 0; j < lines-i; j++){
System.out.print(" ");
}
for(int j = 0; j <= i; j++){
System.out.print(" "+ factorial(i)/(factorial(j) * factorial(i-j)));
}
System.out.println("");
}
}
// Method for Factorial
public static int factorial(int number){
int fact = 1;
int i=1;
while(i <=number){
fact = fact * i;
i++;
}
return fact;
}
}