forked from HarvardWestlake/SourceCodeTest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrixExampleTester.java
More file actions
75 lines (62 loc) · 2.05 KB
/
MatrixExampleTester.java
File metadata and controls
75 lines (62 loc) · 2.05 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
public class MatrixExampleTester {
public static void main(String[] args) {
// Testing matrix multiplication
int[][] matrix1 = {
{ 1, 3, 5 },
{ 3, 5, 7 },
{ 4, 8, 12 }
};
int[][] matrix2 = {
{ 1, 0, 0 },
{ 0, 1, 0 },
{ 0, 0, 1 }
};
int[][] product1 = MatrixExample.multiplyMatrices(matrix1, matrix2);
printMatrix(product1);
int[][] matrix3 = {
{ 2, 7 },
{ 4, 1 },
{ 9, 9 },
{ 5, 1 }
};
int[][] matrix4 = {
{ 8, 1, 3, 4, 8 },
{ 2, 4, 6, 8, 0 }
};
int[][] product2 = MatrixExample.multiplyMatrices(matrix3, matrix4);
printMatrix(product2);
int[][] matrix5 = {
{ 1, 2, 3, 4, 5, 6 },
{ 4, 5, 6, 3, 7, 2 },
{ 27, 8, 9, 5, 3, 21 },
{ 73, 2, 19, 5, 1, 8 },
{ 47, 9, 9, 5, 0, 22 },
{ 78, 86, 1, 4, 1, 21 },
{ 73, 18, 2, 2, 5, 11 }
};
int[][] matrix6 = {
{ 4, 12, 9, 1 },
{ 22, 19, 71, 2 },
{ 3, 55, 81, 47 },
{ 10, 20, 30, 40 },
{ 3, 9, 27, 81 },
{ 11, 21, 20, 7 }
};
int[][] product3 = MatrixExample.multiplyMatrices(matrix5, matrix6);
printMatrix(product3);
// Testing Random Matrices of various sizes
printMatrix(MatrixExample.generateRandomMatrix(3, 3));
printMatrix(MatrixExample.generateRandomMatrix(2, 7));
printMatrix(MatrixExample.generateRandomMatrix(6, 7));
}
static public void printMatrix(int[][] matrix) {
System.out.println("result length: " + matrix.length + " x " + matrix[0].length);
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
System.out.print(matrix[i][j] + " ");
}
System.out.println();
}
System.out.println();
}
}