-
Notifications
You must be signed in to change notification settings - Fork 990
/
2ndOct_roshni-rawat-cs18.java
50 lines (37 loc) · 1.21 KB
/
2ndOct_roshni-rawat-cs18.java
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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int row = input.nextInt();
int column = input.nextInt();
for (int i = 0; i < row; i++) {
StringBuilder strBuild = new StringBuilder();
strBuild.append(new String(new char[i]).replace('\0', ' '));
int index = i;
boolean up = i == row - 1;
while(index < column) {
strBuild.append(index+1);
int gapIndents;
if (up) {
gapIndents = 2 * i - 1;
}
else {
int j = row - i - 1;
gapIndents = 2 * j - 1;
}
strBuild.append(new String(new char[gapIndents]).replace('\0', ' '));
index += gapIndents + 1;
if (i == 0) {
up = false;
}
else if (i == row - 1) {
up = true;
}
else {
up = !up;
}
}
System.out.println(strBuild.toString());
}
}
}