-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranspose.java
More file actions
37 lines (35 loc) · 1.27 KB
/
transpose.java
File metadata and controls
37 lines (35 loc) · 1.27 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
import java.util.Scanner;
public class transpose {
public static void main(String[] args) {
Scanner inp = new Scanner(System.in);
int matrix[][] = new int[3][2];
int trMatrix[][] = new int[2][3];
System.out.println("enter elements of matrix:");
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
System.out.println(i+1+".row "+(j+1) + ".col :");
matrix[i][j] = inp.nextInt();
}
}
System.out.println("original matrix:");
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
System.out.print(matrix[i][j] + " ");
}
System.out.println();
}
System.out.println("transposed matrix :");
for(int i = 0 ; i< matrix.length; i++){
for(int j = 0; j<matrix[i].length; j++){
trMatrix[j][i] = matrix[i][j];
}
}
for (int i = 0; i <trMatrix.length ; i++){
for(int j = 0 ; j<trMatrix[i].length;j++){
System.out.print(trMatrix[i][j] + " ");
}
System.out.println(" ");
}
inp.close();
}
}