-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZigzag.java
More file actions
29 lines (26 loc) · 775 Bytes
/
Zigzag.java
File metadata and controls
29 lines (26 loc) · 775 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.Scanner;
public class Zigzag {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int row = scan.nextInt();
int col = scan.nextInt();
int[][] matrix = new int[row][col];
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
matrix[i][j] = scan.nextInt();
}
}
int sum = 0;
for (int i = 0; i < row; i++) {
if (i == 0 || i == row - 1) {
for (int j = 0; j < col; j++) {
sum += matrix[i][j];
}
} else {
sum += matrix[i][row - i - 1];
}
}
System.out.println(sum);
scan.close();
}
}