Created
August 7, 2012 00:21
-
-
Save pxpc2/3279875 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @param matrixA the first matrix | |
* @param matrixB the second matrix | |
* @return the product | |
*/ | |
private static int[][] getProduct(int[][] matrixA, int[][] matrixB) | |
{ | |
if (matrixA[0].length != matrixB.length) | |
{ | |
System.out.println("[SEVERE] Invalid matrices"); | |
return null; | |
} | |
int[][] finalMatrix = new int[matrixA.length][matrixB[0].length]; | |
for (int i = 0; i < matrixA.length; i++) | |
{ | |
for (int j = 0; j < matrixB[0].length; j++) | |
{ | |
for (int k = 0; k < matrixA[0].length; k++) | |
{ | |
finalMatrix[i][j] += matrixA[i][k] * matrixB[k][j]; | |
} | |
} | |
} | |
return finalMatrix; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment