I have 2d array java, I need to look at it and check on the max value, then print it with the count of how many it is in the array
I was trying to do like this but it doesn't work
int[][] rand = new int[][]{
{1, 80, 3, 4, 5},
{13, 199, 80, 8},
{12, 22, 80, 190}
};
int max = rand[0][0];
int count = 0;
for (int i = 0; i < rand.length; i++){
for (int ii = 0; ii < rand[i].length; ii++) {
if (rand[i][ii] > max) {
max = rand[i][ii];
count++;
}
}
}
System.out.println(max + " " + count);
rand[0][0]will raise an OutOfBoundsException on an empty array.