I am trying to write a method that takes a 2D array parameter and creates from it a 1D array with a length equal to the number of rows in the original array. I also want the elements in the rows of the new array to equal the minimum value from each row of the original array. If the original row is empty, I’d like to have the new array equal 0.0. I’ve written my method below but I am receiving an indexOutOfBounds error and I’m not sure why…. Thanks
enter public double[] newOneD(double[][] x) {
int xrow = x.length;
int xcol = x[0].length;
double[] y = new double[xrow];
int min = 0;
for (int i = 0; i < xrow; i++){
for (int j = 0; j < xcol; j++) {
if(x[i][j] < x[i][min]) {min = j;}
y[i] = x[i][min];}
}
return y;}