Java output the number of scores above or equal to the average -
so have class assignment have let users type values array, average , output number of scores above or equal average, , number of scores below average.
however, figured out average part.
here have far:
public static void main(string[] args) { scanner sc = new scanner(system.in); system.out.println("enter size of array: "); int n = sc.nextint(); int a[] = new int[n]; system.out.println("enter test scores"); for(int = 0; < a.length; i++) { a[i] = sc.nextint(); } int sum = 0; for(int b=0; b < a.length; b++) { sum = sum + a[b]; } double average = ((double)sum) / a.length; system.out.println("the average is"+" " + average); }
i on part output number of scores above or equal average , number of scores below average.
public static void main(string[] args) { scanner sc = new scanner(system.in); system.out.println("enter size of array: "); int n = sc.nextint(); int a[] = new int[n]; system.out.println("enter test scores"); for(int = 0; < a.length; i++) { a[i] = sc.nextint(); } int sum = 0; for(int b=0; b < a.length; b++){ sum = sum + a[b]; } double average = ((double)sum) / a.length; int above = 0; int below = 0; for(int b=0; b < a.length; b++){ if ((double)a[b] > average) { above++; } else if ((double)a[b] < average) { below++; } } system.out.println("the average is"+" " + average); system.out.println("the count of numbers above average " + above); system.out.println("the count of number equal average " + (a.length - below - above)); system.out.println("the count of numbers below average " + below); } }