I have a problem, I have a matrix 5x5
with random numbers from 0 to 1000, I must take the odd numbers from the matrix, add them to a vector and return that vector.
This is the method that should return the vector with the odd numbers
public int[] s() {
for(int i = 0; i<matriz.length; i++) {
for(int j = 0; i < matriz.length; j++) {
if(matriz[i][j] % 2 != 0) {
vector[cont] = matriz[i][j];
cont++;
}
}
}
return vector;
}
The variable cont is initialized to 0 and the size of the vector is the multiplication of rows and columns.
But I have an exception that is the following:
"Exception in thread" main "java.lang.ArrayIndexOutOfBoundsException: 5 "
I guess there is an illegal index but I can not find a way to fix it.