Skip to content

Instantly share code, notes, and snippets.

@pxpc2
Created August 7, 2012 00:21
Show Gist options
  • Save pxpc2/3279875 to your computer and use it in GitHub Desktop.
Save pxpc2/3279875 to your computer and use it in GitHub Desktop.
/**
*
* @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