finds the top two values in an array of positive numbers stored in an array code example
Example: find top 2 values in array list
public static void twoLargest(int values[]){
int largestA = values[0];
int largestB = -1;
for(int i = 0; i < values.length; i++){
if(values[i] > largestA){
largestB = largestA;
largestA = values[i];
}
else if (values[i] > largestB && values[i] != largestA) {
largestB = values[i];
}
}
System.out.println("Largest - " + largestA);
System.out.println("2nd largest Largest - " + largestB);
}