-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSparseMatrixTranspose.java
More file actions
37 lines (31 loc) · 949 Bytes
/
Copy pathSparseMatrixTranspose.java
File metadata and controls
37 lines (31 loc) · 949 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
public class SparseMatrixTranspose {
static int[][] sparse = {
{4, 5, 4},
{0, 1, 10},
{1, 3, 20},
{2, 2, 30},
{3, 4, 40}
};
static int[][] transpose = new int[3][5];
public static void main(String[] args) {
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 3; j++) {
transpose[j][i] = sparse[i][j];
}
}
System.out.println("Original Triplet Matrix (5x3):");
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 3; j++) {
System.out.printf("%4d", sparse[i][j]);
}
System.out.println();
}
System.out.println("\nTranspose of Triplet Matrix (3x5):");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 5; j++) {
System.out.printf("%4d", transpose[i][j]);
}
System.out.println();
}
}
}