File tree 1 file changed +41
-0
lines changed
Course 1 - Introduction to JAVA/Test-2
1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments