try using an enhanced for loop instead of a normal for loop
for example:
package stuff;
public class tester
{
public static void main(String [] args)
{
int[] array = {5,2,7,5,6};
int largest = 0;
//enhanced for loop here
for(int i : array)
{
if(i > largest)
{
largest = i;
}
}
System.out.println(largest);
}
}
This would print out the number 7. the enhanced for loop is for running through an array, list, arraylist, etc... It lasts as long as the length of what you're sorting through. It takes the first value from array, in this case 5, and puts it into " i " and from there, it runs the code in the loop until it runs out of values in the array.