// find the biggest element in an array int a[]. assert a.length > 0 : "only works if there are some elements in the array"; // presume the biggest element is the first one. int biggestSoFar = a[0]; // loop through all elements looking for an even bigger one. for ( int candidate : a ) { if ( candidate > biggestSoFar ) { biggestSoFar = candidate; } } // biggestSoFar now contains the biggest. ///////////////////////////////////////////////////////////////////////////////////////// // if we need to find out where, (which index) the biggest was, you need code like this: assert a.length > 0 : "only works if there are some elements in the array"; // presume the biggest element is the first one. int biggestSoFarIndex = 0; int biggestSoFar = a[0]; // loop through all elements looking for an even bigger one. for ( int i=1; i<a.length; i++ ) { if ( a[i] > biggestSoFar ) { biggestSoFarIndex = i; biggestSoFar = a[i]; } } // When you fall out the bottom of the loop, // biggestSoFarIndex will have index of biggest, // and biggestSoFar will have the biggest value