-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnalyzeNumbers.java
38 lines (36 loc) · 952 Bytes
/
AnalyzeNumbers.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import java.util.Scanner;
public class AnalyzeNumbers {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("How many items do you want in your list?");
int x = input.nextInt();
double[] list = new double[x];
System.out.println("Enter the numbers going into the list.");
double sum = 0;
/*
* This populates the array with user input.
*/
for (int i = 0; i < list.length - 1; i++) {
list[i] = input.nextDouble();
}
/*
* Now to find the average
*/
for (int i = 0; i < list.length - 1; i++) {
sum += list[i];
}
double average = sum / x;
/*
* Now to check to see how many numbers are above the average
*/
int aboveAverage = 0;
for (int i = 0; i < list.length - 1; i++) {
if (list[i] > average) {
aboveAverage++;
System.out.println(list[i]);
}
}
System.out.println("There are: " + aboveAverage
+ " numbers above average.");
}
}