-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTranspose.java
More file actions
40 lines (34 loc) · 927 Bytes
/
Transpose.java
File metadata and controls
40 lines (34 loc) · 927 Bytes
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
package Ganesh;
import java.util.Scanner;
public class Transpose {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the no of rows: ");
int row = sc.nextInt();
System.out.print("Enter the no of columns: ");
int col = sc.nextInt();
int [][] matrix = new int [row][col];
System.out.print("Enter matrix elements: ");
for(int i=0;i<row;i++) {
for(int j=0;j<col;j++) {
matrix[i][j] = sc.nextInt();
}
}
System.out.print("Matrix: ");
System.out.println();
for(int i=0;i<row;i++) {
for(int j=0;j<col;j++) {
System.out.print(matrix[i][j] + "\t");
}
System.out.println();
}
System.out.print("Transposed Matrix: ");
System.out.println();
for(int i=0;i<row;i++) {
for(int j=0;j<col;j++) {
System.out.print(matrix[j][i] + "\t");
}
System.out.println();
}
}
}