public class MaxArray { public static void main(String[] args) { double[] myList = { 1, 4, 9, 3, 7, 5, 6}; double max; // larget value found in array int indexOfMax; // index where the largest value is found // Find max value and its index max = myList[0]; // Assume the 1st element is the largest indexOfMax = 0; // Location of the largest value for ( int i = 1; i < myList.length; i++ ) if ( myList[i] > max ) // Check if myList[i] is "better" { max = myList[i]; // Found a larger value indexOfMax = i; // Remember its location } System.out.println("Max = " + max); System.out.println("Index of Max = " + indexOfMax); } }