-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTranspose_Of_Matrix.java
More file actions
32 lines (30 loc) · 992 Bytes
/
Transpose_Of_Matrix.java
File metadata and controls
32 lines (30 loc) · 992 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
import java.util.*;
public class Transpose_Of_Matrix {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int arr[][] = new int[n][n];
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[0].length; j++) {
arr[i][j] = sc.nextInt();
}
}
transpose(n, arr);
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[0].length; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
sc.close();
}
public static void transpose(int n, int a[][]) {
for (int row = 0; row < a.length; row++) {
for (int col = row + 1; col < a.length; col++) {
int temp = a[row][col];
a[row][col] = a[col][row];
a[col][row] = temp;
}
}
}
}