-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq15.java
More file actions
29 lines (23 loc) · 685 Bytes
/
q15.java
File metadata and controls
29 lines (23 loc) · 685 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
import java.util.*;
public class q15 {
public static void main(String[] args) {
// TODO Auto-generated method stub
LinkedList<Long> list = new LinkedList<Long>();
list.add(Long.valueOf(1));
list.add(Long.valueOf(2));
list.add(Long.valueOf(1));
System.out.println("Value before starting: " + list.toString());
for(int i = 2; i < 40; ++i){
System.out.println("Current Iteration #: " + i + " " + list.toString());
nextRow(list);
}
System.out.println(list.get(list.size()/2));
}
public static void nextRow(LinkedList<Long> x){
x.add(Long.valueOf(1));
for(int i = x.size() - 2; i > 0; --i){
x.set(i, x.get(i) + x.get(i - 1));
}
return;
}
}