import java.util.Scanner;
public class AverageArray {
public static void main(String[] args) {
final int TOTAL_NUMBERS = 10;
int[] numbers = new int[TOTAL_NUMBERS];
float sum;
//Create a Scanner
Scanner input = new Scanner(System.in);
//Read all numbers
for (int i = 0; i < numbers.length; i++) {
System.out.print("Enter a number:");
//Conver String into integer
numbers[i] = input.nextInt();
}
//Find the sum and average
for (int i = 0; i < numbers.length; i++){
sum += numbers[i];
int average = sum / TOTAL_NUMBERS;
}
//Find the number of values in the array greater than the average
int maxAverage = 0;
for (int i = 0; i < numbers.length; i++) {
if (numbers[i] > average) maxAverage++;
}
//Prepare the result
String output = "The array is";
for (int i = 0; i < numbers.length; i ++) {
output += numbers[i] + " ";
}
output += "\nThe average is" + average;
output += "\nThe number of values in the array greater than the average" + "is" + maxAverage;
//Display the result
System.out.println(output);
}
}
Error:
AverageArray.java:25: possible loss of precision
found : float
required: int
int average = sum / TOTAL_NUMBERS;
^
AverageArray.java:32: cannot find symbol