Skip to content

Commit 3db41f6

Browse files
authored
Merge pull request #76 from arpitjain22june/patch-8
Create WavePrintRowWise.java
2 parents ef8f39a + d9b3130 commit 3db41f6

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Take as input a two-d array. Wave print it row-wise.
2+
3+
Input Format
4+
Two integers M(row) and N(column) and further M * N integers(2-d array numbers).
5+
6+
Constraints
7+
Both M and N are between 1 to 10.
8+
9+
Output Format
10+
All M * N integers are seperated by commas with 'END' written in the end(as shown in example).
11+
12+
Sample Input
13+
4 4
14+
11 12 13 14
15+
21 22 23 24
16+
31 32 33 34
17+
41 42 43 44
18+
Sample Output
19+
11, 12, 13, 14, 24, 23, 22, 21, 31, 32, 33, 34, 44, 43, 42, 41, END
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import java.util.Scanner;
2+
3+
public class WavePrintRowWise {
4+
5+
public static void main(String[] args) {
6+
// TODO Auto-generated method stub
7+
Scanner sc = new Scanner(System.in);
8+
int n = 0, m = 0;
9+
if (sc.hasNext()) {
10+
m = sc.nextInt();
11+
}
12+
n = sc.nextInt();
13+
int[][] arr = new int[m][n];
14+
for (int i = 0; i < m; i++) {
15+
for (int j = 0; j < n; j++) {
16+
arr[i][j] = sc.nextInt();
17+
}
18+
}
19+
for (int i = 0; i < m; i++) {
20+
if (i % 2 == 0) {
21+
for (int j = 0; j < n; j++) {
22+
System.out.print(arr[i][j] + ", ");
23+
}
24+
} else {
25+
for (int j = n - 1; j >= 0; j--) {
26+
System.out.print(arr[i][j] + ", ");
27+
}
28+
}
29+
30+
}
31+
System.out.println("END");
32+
}
33+
34+
}

0 commit comments

Comments
 (0)