Using the array scores you have declared in Question 1, write the segment of code to compute and display the second highest score in the array (The second highest score should not be the same as the highest score. In the array score, since there are 2 students having the same highest score, the second highest score should be 91.)
This is the program for Question 1:
public class ComputeScore {
public static void main(String [ ] args) {
int scores [ ] = {74,62,54,95,45,36,91,75,64,95};
for(int j=0; j<scores.length; j++) {
System.out.println("Scores in the array are: " + scores[ j ]);
}
int high = scores[0];
for(int j=1; j<scores.length; j++) {
if (high < scores[j]) {
high = scores[j];
}
}
double sum=0;
for (int j=0; j<scores.length; j++) {
sum+=scores[j];
}
double average = (sum/scores.length);
System.out.println("The average is " + average);
System.out.println("The highest score is " + high);
=====================
I have no idea on how to make use of the solution in Question 1 to write the codes to compute and display the second highest score in the array.
Please render me your help and explain too thank you (:
Tags: