forked from HarryDulaney/intro-to-java-programming
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExercise07_04.java
63 lines (38 loc) · 1.43 KB
/
Exercise07_04.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package ch_07;
/*7.4 (Analyze scores) Write a program 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 100.
*/
import java.util.Scanner;
public class Exercise07_04 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double[] scores = new double[100];
int count = 0;
double sum = 0;
System.out.println("Enter a new score (enter a negative number"
+ " to complete program): ");
for (int i = 0; i < 100; i++) {
double score = in.nextDouble();
if (score < 0) break;
scores[i] = score;
count++;
sum += scores[i];
}
double average = sum / count;
int aboveorequal = 0;
for (int i = 0; i <= count; i++) {
if (scores[i] >= average) {
aboveorequal++;
}
}
System.out.println("Count is: " + count);
System.out.printf("The average is %1.2f \n", average);
System.out.println("Number of scores above or equal to average is: "
+ aboveorequal);
System.out.println("Number of scores below the average is:"
+ " " + (count - aboveorequal));
}
}