Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Apr 15, 2020. It is now read-only.

Latest commit

 

History

History
History
56 lines (35 loc) · 1.21 KB

File metadata and controls

56 lines (35 loc) · 1.21 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import java.util.ArrayList;
/*
* Program focusing on returning the Pascal triangle as an ArrayList!
*/
public class Test {
static ArrayList<ArrayList<Integer>> pascalTriangle(int A){
ArrayList<ArrayList<Integer>> rows = new ArrayList<>();
int[][] arr = new int[A][A];
for(int i=0; i<A; i++){
for(int j=0; j<=i; j++){
if(i==j || j==0)
arr[i][j] = 1;
else
arr[i][j] = arr[i-1][j] + arr[i-1][j-1];
}
}
for(int i=0; i<A; i++){
ArrayList<Integer> row = new ArrayList<>();
for(int j=0; j<=i; j++){
row.add(arr[i][j]);
}
rows.add(row);
}
return rows;
}
public static void main(String[] args) {
ArrayList<ArrayList<Integer>> arr = pascalTriangle(8);
for(int i=0; i<arr.size(); i++){
for(int j=0; j<i+1; j++){
System.out.print(arr.get(i).get(j)+" ");
}
System.out.println("");
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.