How to get min/Max value of a all column in a two-dimensional arra
so for example, lets say you have the following 2d array:
1 2 3
4 5 6
7 8 9
Than the out put should be:
-- col 1 --
min value at col 1 is 1
max value at col 1 is 7
-- col 2 --
min value at col 2 is 2
max value at col 2 is 8
-- col 3 --
min value at col 3 is 3
max value at col 3 is 9
public static void col(int[][] array) {
for (int i = 0; i < array.length; i++) {
int minValue = array[i][0];
int maxValue = array[i][0];
for (int j = 0; j < array[i].length; j++) {
if (minValue > array[j][i]) {
minValue = array[j][i];
}
if (maxValue < array[j][i]) {
maxValue = array[j][i];
}
}
}
}
getting an error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3