Skip to content

Commit 4fa9916

Browse files
committed
Jan22
1 parent a5efcd0 commit 4fa9916

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/Jan22/Read2dArray.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}

0 commit comments

Comments
 (0)