File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ package Jan22 ;
2
+ import java .util .Scanner ;
3
+ public class Read2dArray {
4
+ public static void main (String [] args ) {
5
+ Scanner scan = new Scanner (System .in );
6
+ System .out .println ("Enter the number of rows" );
7
+ int row = scan .nextInt ();
8
+ System .out .println ("Enter the number of columns" );
9
+ int col = scan .nextInt ();
10
+ int [][] a = new int [row ][col ];
11
+ System .out .println ("Enter the elements of the matrix" );
12
+ for (int i =0 ;i <row ;i ++) {
13
+ for (int j =0 ;j <col ;j ++) {
14
+ a [i ][j ]=scan .nextInt ();
15
+ }
16
+ }
17
+ scan .close ();
18
+ print (a ,row ,col );
19
+ }
20
+ private static void print (int [][] a ,int row ,int col ) {
21
+ for (int i =0 ;i <row ;i ++) {
22
+ for (int j =0 ;j <col ;j ++) {
23
+ System .out .print (a [i ][j ]+" " );
24
+ }
25
+ System .out .println ();
26
+ }
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments