public static int[][] multiply2DMatrix(int[][] firstMatrix,
int[][] secondMatrix) {
int[][] result = new int[firstMatrix.length][secondMatrix[0].length];
if (firstMatrix[0].length == secondMatrix.length) {
for (int i = 0; i < firstMatrix.length; i++) {
for (int j = 0; j < secondMatrix[0].length; j++) {
for (int k = 0; k < firstMatrix[0].length; k++) {
result[i][j] += firstMatrix[i][k] * secondMatrix[k][j];
}
}
}
} else {
throw new RuntimeErrorException(null,
"Column number of first matrix" + "("
+ firstMatrix[0].length
+ ") is not equal to row number" + "("
+ secondMatrix.length + ") of second matrix");
}
return result;
}
EasyMath.java 文件源码
java
阅读 28
收藏 0
点赞 0
评论 0
项目:easyMath
作者:
评论列表
文章目录