Reputation: 13
I wrote a method to get the maximum number in the queue , but I need to return the location of the maximum number in the queue . this is the max method I wrote :
public int maxValue(int[] array) {
int maximum = array[0];
for (int i = 0; i < array.length; i++) {
if (array[i] > maximum) {
maximum = array[i];
}
}
return maximum;
}
Upvotes: 0
Views: 59
Reputation: 48837
Use a int maximumIndex
besides:
int maximumIndex = 0;
...
maximumIndex = i;
...
return maximumIndex;
Upvotes: 3