Hola, me piden hacer un método que sume 2 matrices, y a mí se me ocurrió hacerlo así, pero a la hora de probarlo me tira error, me tira que el error está en
matrisResultado[j] = matrisA[j] + matrisB[ib][jb];
, pero no logro corregirlo, alguien puede darme una mano?
public int[][] sumarOtraMatris(int[][] matrisA , int[][] matrisB) {
int[][] matrisResultado = null;
if(matrisA.length == matrisB.length) {
for(int i = 0; i < matrisA.length ; i++) {
for(int ib = 0; ib < matrisB.length ; i++) {
for(int j = 0; j < matrisA[0].length ; j++) {
for(int jb = 0; jb < matrisB[0].length ; jb++) {
if(i==ib && j==jb) {
matrisResultado[i][j] = matrisA[i][j] + matrisB[ib][jb];
}
}
}
}
}
} else {
throw new Error("Las matrises deben tener la misma cantidad de filas que columnas");
}
return matrisResultado;