/*
não consigo fazer esse metodo funcionar da erro Index 4 out of bounds for length 4
*/
public class MultArray {
static public void sum(int[][] a, int[][] b){
int rows = a[0].length/2;
int colums = a[1].length;
int[][] soma = new int[rows ][colums ];
for(int i = 0; i < rows; i++){
for(int j = 0; i < colums ; j++){
soma[i][j]= a[i][j] + b[i][j];
}
}
System.out.println("sum of matrizes is : ");
for(int[] index: soma){
for(int elementos: index){
System.out.print(elementos+ " ");
}
System.out.println("");
}
}
public static void main(String args[]) {
int[][] first = { { 2, 3, 4,-6 }, { 5, 2, 3,0} };
int[][] second = { { -4, 5, 3,7 }, { 5, 6, 3,1 } };
sum(first , second );
}
}
Acho que isso
int rows = a[0].length/2;
int colums = a[1].length;
Deveria ser
int rows = a.length;
int colums = a[0].length;
Se reparar bem nessa linha
for(int j = 0; i < colums ; j++){
Na condição, você colocou i no lugar de j.
E column possui um n no final então columns seria mais correto.
Bom dia jgus e muito obrigado o erro foi essa troca do j pelo i , fiquei a noite toda ontem e não descobrir, o noite frustrante rsrs
Muito obrigado.