-
Notifications
You must be signed in to change notification settings - Fork 0
/
AboveAverage.java
42 lines (31 loc) · 1.11 KB
/
AboveAverage.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
// open.kattis.com/problems/aboveaverage
import java.util.Scanner;
public class AboveAverage {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int numCases = in.nextInt();
in.nextLine();
System.out.println();
for (int p = 0; p < numCases; p++) {
int numStudents = in.nextInt();
int[] grades = new int[numStudents];
double average = 0;
for (int i = 0; i < numStudents; i++) {
grades[i] = in.nextInt();
average += grades[i];
}
in.nextLine();
average /= numStudents;
int count = 0;
for (int i = 0; i < grades.length; i++) {
if (grades[i] > average) {
count++;
}
}
double num = (double) count / numStudents;
num *= 100;
System.out.println(String.format("%.3f", num) + "%");
}
}
}