Skip to content

Commit 68d6555

Browse files
matrix
1 parent fc25513 commit 68d6555

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

matrix.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import java.util.Scanner;
2+
public class matrix {
3+
public static void main(String[] args) {
4+
Scanner scanner = new Scanner(System.in);
5+
6+
System.out.print("Enter number of rows: ");
7+
int rows = scanner.nextInt();
8+
System.out.print("Enter number of columns: ");
9+
int cols = scanner.nextInt();
10+
11+
int[][] matrix = new int[rows][cols];
12+
13+
System.out.println("Enter matrix elements:");
14+
for (int i = 0; i < rows; i++) {
15+
for (int j = 0; j < cols; j++) {
16+
matrix[i][j] = scanner.nextInt();
17+
}
18+
}
19+
20+
System.out.println("The matrix is:");
21+
for (int i = 0; i < rows; i++) {
22+
for (int j = 0; j < cols; j++) {
23+
System.out.print(matrix[i][j] + " ");
24+
}
25+
System.out.println();
26+
}
27+
28+
scanner.close();
29+
}
30+
}

0 commit comments

Comments
 (0)