-
Notifications
You must be signed in to change notification settings - Fork 153
/
Copy pathTranspose.java
43 lines (38 loc) · 1.2 KB
/
Transpose.java
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
/**
* Print Transpose
*/
import java.util.*;
class Transpose {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
System.out.print("Enter the number of rows: ");
int row = input.nextInt();
System.out.print("Enter the number of columns: ");
int col = input.nextInt();
// Input the array
int[][] arr = new int[row][col];
System.out.println("Enter the elements: ");
for (int i=0; i<row; i++) {
for (int j=0; j<col; j++) {
System.out.print("arr[" + i + "][" + j + "] = ");
arr[i][j] = input.nextInt();
}
}
// Print original matrix
System.out.println("Input matrix: ");
for (int i=0; i<row; i++) {
for (int j=0; j<col; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println("");
}
// Print Transpose matrix
System.out.println("Transpose of Input matrix: ");
for (int i=0; i<row; i++) {
for (int j=0; j<col; j++) {
System.out.print(arr[j][i] + " ");
}
System.out.println("");
}
}
}