-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrixTransform.java
More file actions
57 lines (36 loc) · 1.06 KB
/
Copy pathMatrixTransform.java
File metadata and controls
57 lines (36 loc) · 1.06 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Program rotates a Symmetric Matrix 90 degrees
*/
public class MatrixTransform {
public static void main(String[] args) {
/* Declare variables */
int[][] matrix = new int[6][6];
/* Populate Matrix */
for(int i =0; i < 6; i++){
for(int j = 0; j < 6; j++){
matrix[i][j] = i+j;
System.out.print(matrix[i][j] + "\t");
}
System.out.println();
}
/* Declare additional variables */
int rows = matrix.length;
int columns = matrix[0].length;
int[][] newMatrix = new int[rows][columns];
System.out.println("\n" + "....Transforming...." + "\n");
/* Do transfomation
*
* for each row, i, create a new matrix that transforms the row into a column in the new matrix, i.
*
*
*/
for(int i = 0; i < rows; i++){
for(int j = columns - 1; j >= 0; j--){
newMatrix[i][columns - 1 - j] = matrix[j][i];
// System.out.println(i + "," + (columns - 1 - j) + "->" + j + "," + i);
System.out.print(newMatrix[i][columns- j - 1] + "\t");
}
System.out.println();
}
}
}