forked from shijiebei2009/Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrix.java
38 lines (36 loc) · 966 Bytes
/
Matrix.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
package cn.codepub.algorithms.matrix;
/**
* <p>
* Created with IntelliJ IDEA. 2015/10/10 20:37
* </p>
* <p>
* ClassName:Matrix
* </p>
* <p>
* Description:方阵的乘法
* </P>
*
* @author Wang Xu
* @version V1.0.0
* @since V1.0.0
*/
public class Matrix {
static int[][] a = new int[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
static int[][] b = new int[][]{{1, 2, 3}, {1, 2, 3}, {1, 2, 3}};
static int[][] c = new int[a.length][b.length];
public static void main(String[] args) {
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < a[i].length; j++) {
for (int k = 0; k < b[j].length; k++) {
c[i][j] += a[i][k] * b[k][j];
}
}
}
for (int temp[] : c) {
for (int col : temp) {
System.out.print(col + "\t");
}
System.out.println();
}
}
}