-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSWEA2005.java
More file actions
49 lines (33 loc) · 873 Bytes
/
SWEA2005.java
File metadata and controls
49 lines (33 loc) · 873 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
42
43
44
45
46
47
48
49
package com.study.code.solved;
import java.util.Scanner;
public class SWEA2005 {
private static Scanner sc;
public static void main(String[] args) {
sc = new Scanner(System.in);
int tcN = sc.nextInt();
for (int tc = 1; tc <= tcN; tc++) {
System.out.println("#" + tc);
int sizeOfTriangle = sc.nextInt();
int[] arrPast = new int[10];
int[] arrCurr = new int[10];
for(int i =0; i < sizeOfTriangle; i++) {
for(int j = 0; j <= i; j++) {
if(j == 0 || j == i) {
System.out.print("1");
arrPast[j] = 1;
arrCurr[j] = 1;
}else {
System.out.print(arrPast[j-1] + arrPast[j]);
arrCurr[j] = arrPast[j-1] + arrPast[j];
}
System.out.print(" ");
}
for(int j = 0; j <= i; j++) {
arrPast[j] = arrCurr[j];
}
System.out.println();
}
}
sc.close();
}
}