been working at a Java problem for a while now. Having some issue with getting the array index that corresponds to the highest value. I'm pretty sure I understand the logic behind doing so, as I successfully retrieved the index that contained the lowest value. This is what I have:
public static void main(String[] args) {
double array[] = {1.12, 2.24, 3.36, 0.48, 2.00, 5.00, 12.12, 1.48, 3.12, 3.24, 6.6, 1.12};
double highestValue = array[0];
int highIndex = 0;
for (int i = 0; i < array.length; i++) {
if (array[i] > highestValue)
highIndex = i;
}
System.out.println(highIndex);
}
However, for this array, my code returns an index of 10, which corresponds to 6.6. But the highest value in the array is 12.12 at index 6. Any reasons why I keep getting 10 as the highest index? The code works fine for retrieving the lowest index if I reverse the logic, but I'm not sure what I'm doing wrong here. Thanks for any help.