-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransposeOfMatrix.java
More file actions
46 lines (39 loc) · 1.3 KB
/
TransposeOfMatrix.java
File metadata and controls
46 lines (39 loc) · 1.3 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import java.util.Scanner;
public class TransposeOfMatrix {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int m, n;
System.out.print("Enter the number of Rows: ");
m = scan.nextInt();
System.out.print("Enter the number of Columns: ");
n = scan.nextInt();
int arr[][] = new int[m][n];
int transpose[][] = new int[n][m];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
System.out.print("Enter Element for row " + i + " and column " + j + ": ");
arr[i][j] = scan.nextInt();
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
transpose[j][i] = arr[i][j];
}
}
System.out.println("Normal Matrix: ");
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 of Matrix: ");
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
System.out.print(transpose[i][j] + " ");
}
System.out.println();
}
scan.close();
}
}