
8.3 Aggregate Array Operations 479
28 + priceFormat.format( cellBills[maxIndex])
29 + ", was found at index " + maxIndex );
30 }
31 }
EXAMPLE 8.6 Finding a Maximum Value in an Array
We start by assuming that the first element is a maximum value. So we ini-
tialize an integer variable, maxIndex, to 0, at line 19. Then, at lines 20–24,
starting at element 1, we step through the array, comparing the value of
each element with the element at maxIndex. Whenever we find a value
higher than the current maximum, we assign its index to maxIndex (line
23). When the for loop completes, maxIndex holds the index of the array
element with a highest value. We then print ...