-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay18.java
More file actions
41 lines (41 loc) · 1006 Bytes
/
Copy pathDay18.java
File metadata and controls
41 lines (41 loc) · 1006 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
35
36
37
38
39
40
41
import java.util.*;
public class Day18{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the size of the array");
int size =in.nextInt();
System.out.println("Enter the elements of the array");
int arr[] = new int[size];
for(int i=0;i<size;i++){
arr[i] = in.nextInt();
}
String out[][] = new String[size][size];
for (int i=0;i<size ;i++ ) {
for (int j=0;j<size ;j++ ) {
out[i][j] = "";
}
}
for (int j=0;j<size ;j++ ) {
out[0][j] = Integer.toString(arr[j]);
}
int sum=0 ;
for (int i=1;i<size ;i++ ) {
for (int j=0;j<size-i ;j++ ) {
sum = Integer.parseInt(out[i-1][j]) + Integer.parseInt(out[i-1][j+1]);
out[i][j] = Integer.toString(sum);
}
}
for (int i=size-1;i>=0 ;i-- ) {
System.out.print("[");
for (int j=0;j<size ;j++ ) {
if (out[i][j]=="") {
break;
}else{
System.out.print(out[i][j]+", ");
}
}
System.out.print("]");
System.out.println();
}
}
}