Jre Tom
Jre Tom

Reputation: 13

Method to get the location of the maximum number in the queue

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

Answers (1)

sp00m
sp00m

Reputation: 48837

Use a int maximumIndex besides:

int maximumIndex = 0;
...
        maximumIndex = i;
...
return maximumIndex;

Upvotes: 3

Related Questions