Write a program that inputs 20 integers and stores them inside an array. Then, calculate the average of the numbers. Finally, use a for loop to find the sum of all the integers in the array that are greater than the average, and print this sum out.
top of page
bottom of page
class Main { public static void main(String[] args) { int[] numbers = new int[20]; Scanner sc = new Scanner(System.in); for (int i = 0; i < 20; i++) { int a = sc.nextInt(); numbers[i] = a; } sc.close(); int add = 0; for (int i = 0; i < 20; i++) { add = numbers[i] + add; } int add1 = 0; int avg = add / 20; for (int i = 0; i < 20; i++) { if (numbers[i] > avg) { add1 = numbers[i] + add1; } } System.out.println(add1); } }