In: Computer Science
Code in 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
Code Screenshot :
Executable Code:
import java.util.Scanner;
import java.util.Arrays;
public class Main
{
public static void main(String[] args)
{
//Declaring required
variables
int n;
double sum = 0;
Scanner s = new
Scanner(System.in);
//Declaring an
array
int a[] = new int[7];
//Prompting the user for
input
System.out.println("Enter all the
grades:");
//Reading array
values
for(int i = 0; i < 7; i++)
{
a[i] =
s.nextInt();
}
//Sorting the
array
Arrays.sort(a);
//Printing the array after
sorting
System.out.println("Array after
sorting : "+Arrays.toString(a));
//Calculating the
sum
for(int i = 1; i < 7; i++)
{
sum+=a[i];
}
//Printing the average
after dropping lowest grade
System.out.println("Average
:"+sum/6);
}
}
Sample Output :
Please comment
below if you have any queries.
Please do give a thumbs up if you liked the answer thanks
:)