-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem1.java
More file actions
32 lines (29 loc) · 999 Bytes
/
Copy pathProblem1.java
File metadata and controls
32 lines (29 loc) · 999 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
import java.util.Scanner;
public class Problem1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int rowsAndcols = Integer.parseInt(input.nextLine());
int[][] size = new int[rowsAndcols][rowsAndcols];
int currentNum = 1;
for (int col = 0; col < rowsAndcols; col++) {
if(col%2 == 0){
for (int row = 0; row < rowsAndcols; row++) {
size[col][row] = currentNum;
currentNum++;
}
}
else{
for (int row = rowsAndcols-1; row >= 0; row--) {
size[col][row] = currentNum;
currentNum++;
}
}
}
for (int row = 0; row < rowsAndcols; row++) {
for (int col = 0; col < rowsAndcols; col++) {
System.out.print(size[col][row] + " ");
}
System.out.println();
}
}
}