I am trying to create a method that returns the product of two arrays passed as parameter. The method is only working for square matrices and not for two 2x3 and 3x2 matrices, for example. If anyone can help and tell you where the error is, I thank you.
public static int[][] calculaProduto(int[][] a, int[][] b) {
int[][] result = new int[ a.length ][ b[0].length ];
for (int i = 0; i < a.length; i++) {
for (int j = 0; j < b[0].length; j++) {
int somatoria = 0;
for (int k = 0; k < a.length; k++) {
// A: (0x0) * B:(0x0) + A:(0x1) * B:(1x0)...
//
//
int produto = a[j][k] * b[k][j];
somatoria += produto;
result[i][j] = somatoria;
}
}
}
return result;
}