In: Computer Science
Write a Java program that will first ask the user how many grades they want to enter. Then use a do…while loop to populate an array of that size with grades entered by the user. Then sort the array. In a for loop read through that array, display the grades and total the grades. After the loop, calculate the average of those grades and display that average.
Specifications
import java.util.Arrays;
import java.util.Scanner;
public class ArraySumAvg{
public static void main (String args[])
{
double sum=0;
Scanner sc = new
Scanner (System.in);
System.out.print("Enter how many grades you want: ");
int
n=sc.nextInt();
System.out.print("Enter Array elements: ");
int[] arr=new
int[n];
for(int
i=0;i<n;i++)
{
arr[i]=sc.nextInt();
}
//sort
array
Arrays.sort(arr);
System.out.println("Array is after sort: ");
int i=0;
//populate the
array using do..while loop
do
{
System.out.print(arr[i]+" ");
i++;
}
while(i<n);
//average of
grade
for(i=0;i<n;i++)
{
sum+=arr[i];
}
double
avg=sum/n;
System.out.println();
System.out.println("Average is: "+avg);
}
}