-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTwoD.java
More file actions
30 lines (27 loc) · 838 Bytes
/
Copy pathTwoD.java
File metadata and controls
30 lines (27 loc) · 838 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
import java.io.*;
import java.util.*;
public class TwoD{
public static void main(String[] args) throws Exception {
// write your code here
Scanner scn = new Scanner(System.in);
int[][] arr = new int[2][3];
for(int i = 0; i < arr.length; i ++) {
for(int j = 0; j < arr[0].length; j ++) {
arr[i][j] = scn.nextInt();
}
}
wave(arr);
}
public static void wave(int[][] arr) {
int c = 0;
while(c < arr[0].length) {
if(c % 2 == 0) {
for(int r = 0; r < arr.length; r++) System.out.print(arr[r][c]+" ");
} else {
for(int r = arr.length - 1; r >= 0; r--) System.out.print(arr[r][c]+ " ");
}
System.out.println();
c ++;
}
}
}