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
62
63
64 |
package AnalyzeScores;
import javax.swing.JOptionPane;
public class AnalyzeScores {
public static void main(String[] args) {
double[] scores = new double[20];
double total = 0;
String input = "";
int count = 0;
int above = 0;
while(count<=20&&input!=null){
input = JOptionPane.showInputDialog("Enter score #"+(count+1)+
" (Cancel or -1 to end)");
if (input==null)
continue; if(input.equals("-1")){
System.out.println("negative");
input = null;
break;
}
System.out.println(input);
scores[count] = Double.parseDouble(input);
count++;
}
for (int i = 0; i<count; i++)
total = total+scores[i];
for(int i=0; i<count; i++)
if(scores[i]>=(total/count)) above++;
String message = "Average of " + count + " scores: "+ (total/count) + "\n" +
"The number of scores above or equal to the average: " + above + "\n" +
"The number of scores below the average: "+ (count-above);
if(count>0)
JOptionPane.showMessageDialog(null, message);
}
} |