In: Computer Science
Write a java code that gets student test scores from the user. Each test score will be an integer in the range 0 to 100. Input will end when the user enters -1 as the input value. After all score have been read, display the number of students who took the test, the minimum score, the maximum score, the average score (with decimal point, and the number of A where an A is a score in the range 90-100.
//MinMaxAvgScore.java import java.util.Scanner; public class MinMaxAvgScore { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n; int min = Integer.MAX_VALUE,max = Integer.MIN_VALUE,sum = 0; double avg; int i = 0, gradeA = 0; System.out.print("Enter score in the range 0 to 100: "); n=sc.nextInt(); while (n!=-1){ i++; if(min>n){ min = n; } if(max<n){ max = n; } sum += n; if(n>90){ gradeA += 1; } System.out.print("Enter score in the range 0 to 100: "); n=sc.nextInt(); } if(i>0) { avg = sum / i; System.out.println("Number of tests: "+i); System.out.println("Minimum score: "+min); System.out.println("Maximum score: "+max); System.out.println("Average score: "+avg); System.out.println("Number of grade A scores: "+gradeA); } } }