Skip to content

Commit aa5eb11

Browse files
authored
Create Print2DArray.java
1 parent d314b5e commit aa5eb11

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
Given a 2D integer array with n rows and m columns. Print the 0th row from input n times, 1st row n-1 times…..(n-1)th row will be printed 1 time.
3+
Input format :
4+
Line 1 : No of rows(n) & No of columns(m) (separated by space)
5+
Line 2 : Row 1 elements (separated by space)
6+
Line 3 : Row 2 elements (separated by space)
7+
Line 4 : and so on
8+
9+
Sample Input :
10+
3 3
11+
1 2 3
12+
4 5 6
13+
7 8 9
14+
Sample Output :
15+
1 2 3
16+
1 2 3
17+
1 2 3
18+
4 5 6
19+
4 5 6
20+
7 8 9
21+
*/
22+
23+
public class Print2DArray {
24+
public static void print2DArray(int input[][]) {
25+
// Write your code here
26+
for (int i=0;i<input.length;i++)
27+
{
28+
int count = input.length-i;
29+
while (count>0)
30+
{
31+
for (int j=0;j<input[0].length;j++)
32+
{
33+
System.out.print(input[i][j] + " ");
34+
}
35+
count--;
36+
System.out.println("");
37+
}
38+
}
39+
40+
}
41+
}

0 commit comments

Comments
 (0)