In: Computer Science
(JAVA) A class allows students to drop their lowest of 7 quiz grades at the end of the semester. Prompt the user for these values and add them to an array of integer type. Sort the array using the sort method from the standard Java library. Output the student’s average with the lowest score dropped.
import java.util.Arrays;
import java.util.Scanner;
public class AverageDrop {
public static void main(String[] args) {
//creating array to hold 7 scores
int []scores = new int[7];
Scanner sc = new Scanner(System.in);
//reading 7 scores from user
System.out.println("Enter 7 scores: ");
for(int i=0;i<scores.length;i++) {
scores[i]=sc.nextInt();
}
//sorting the scores array using Java library sort()
Arrays.sort(scores);
double total=0;
//finding the total by droping the lowest score which is at index =0
for(int i=1;i<scores.length;i++)
total+=scores[i];
//finding the average with 6 as we droped lowest score
double average = total /6;
System.out.printf("Average: %.2f",average);
}
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
Please Like and Support me as it helps me a lot