-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransposeMatrix.java
More file actions
32 lines (31 loc) · 1.11 KB
/
TransposeMatrix.java
File metadata and controls
32 lines (31 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.io.*;
public class TransposeMatrix {
public static void main() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("ENTER THE NUMBER OF ROWS =");
int m = Integer.parseInt(br.readLine());
System.out.println("ENTER THE NUMBER OF COLUMNS =");
int n = Integer.parseInt(br.readLine());
int arr[][] = new int[m][n];
System.out.println("ENTER THE ELEMENTS=");
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
arr[i][j] = Integer.parseInt(br.readLine());
}
}
System.out.println("MATRIX IS=");
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
System.out.println("TRANSPOSE MATRIX IS=");
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
System.out.print(arr[j][i] + " ");
}
System.out.println();
}
}
}