-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPascalTriangle.java
More file actions
32 lines (25 loc) · 816 Bytes
/
PascalTriangle.java
File metadata and controls
32 lines (25 loc) · 816 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
import java.util.ArrayList;
import java.util.List;
public class PascalTriangle {
public static void main (String[]args){
System.out.println(generate(5));
}
public static List<List<Integer>> generate(int numRows)
{
List<List<Integer>> allrows = new ArrayList<List<Integer>>();
List<Integer> row = new ArrayList<Integer>();
for(int i=0;i<numRows;i++)
{
row.add(0, 1);
System.out.println(row);
System.out.println(row.size());
for(int j=1;j<row.size()-1;j++) {
row.set(j, row.get(j) + row.get(j + 1));
System.out.println(row);
}
allrows.add(new ArrayList<Integer>(row));
System.out.println(allrows);
}
return allrows;
}
}