-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTranspose.java
41 lines (34 loc) · 1.06 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
// 13. Transpose of a matrix
// Write a JAVA program to display transpose of a given matrix.
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 and columns of the matrix : ");
int r = sc.nextInt();
int c = sc.nextInt();
int[][] arr = new int[r][c];
System.out.println("enter the element of matrix");
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
arr[i][j] = sc.nextInt();
}
}
System.out.println("Entered matrix is : \n");
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
System.out.print(arr[i][j] + "\t");
}
System.out.println("\n");
}
System.out.print("\n");
System.out.println("transpose matrix is : \n");
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
System.out.print(arr[j][i] + "\t");
}
System.out.println("\n");
}
System.out.print("\n");
}
}