public class BestTwo
{
private static void swap(int [] num, int i, int j)
{
int tmp = num[i];
num[i] = num[j];
num[j] = tmp;
}
static void sort(int [] num)
{
for(int i = 0; i < num.length-1; i++)
{
// First find the index of the largest element
int maxIndex = i;
for(int j = i; j < num.length; j++)
if(num[j] > num[maxIndex])
maxIndex = num[j];
// Swap the largest with the current position
swap(num, i, maxIndex);
}
}
public static void main(String [] args)
{
int [] num = new int[6];
System.out.print("Enter marks:");
for(int x = 0; x < num.length; x++)
num[x] = Console.readInt();
// Call the sort method ...
sort(num);
// the array is now sorted ... print it out
System.out.println();
for(int i = 0; i < num.length -5; i++)
System.out.println("The two best marks are " + num[0] + " and " + num[1] + ".");
}
}