Write a program in Java that reads an unspecified number of scores and determines how many scores are above or equal to the average and how many scores are below the average. Enter a negative number to signify the end of the input. Assume that the maximum number of scores is 10.
Explanation / Answer
import java.util.*; class count{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int input = 0; int count = 0; int sum = 0; double mean = 0.0; int bavg = 0; int aavg = 0; int[] array = new int[11]; System.out.print("Enter a number between 1 to 10: "); input = sc.nextInt(); while(input >=0){ sum += input; array[input]++; count ++; System.out.print("Enter a number between 1 to 10: "); input = sc.nextInt(); } mean = sum/count; for(int i =0; i = mean; i--){ aavg += array[i]; } System.out.println("number of score above or equal to average : "+aavg); System.out.println("number of score below average : "+bavg); } }