-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlgo_22.java
More file actions
56 lines (40 loc) · 1.08 KB
/
Copy pathAlgo_22.java
File metadata and controls
56 lines (40 loc) · 1.08 KB
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
package algo03;
// 학생수와 점수들 입력 후 평균보다 넘은 학생들의 비율 출력
public class Algo_22 {
public static double average(int std, int[] score) {
int total = 0;
double average = 0;
double count = 0;
for(int i = 0; i < score.length; i++) {
total += score[i];
}
// 평균 점수
average = total / std;
for(int i = 0; i < score.length; i++) {
if( score[i] > average ) {
count += 1;
}
}
return (count/std)*100;
}
public static void main(String[] args) {
int std = 7;
int[] score = {100, 95, 90, 80, 70, 60, 50};
double a = average(std, score);
System.out.println(a);
// 정답
int[] in = {7, 100, 95, 90, 80, 70, 60, 50};
int sum = 0;
for(int i = 0; i < in.length; i++ ) {
sum += in[i];
}
double avg = (double)sum / in[0]; // int 나누기 int 는 int 가 되어버리므로 더블형으로 강제 업 캐스팅을 해버리기
int count = 0;
for(int i = 1; i < in.length; i++) {
if( in[i] > avg ) {
count++;
}
}
System.out.println( ( count)/in[0] * 100);
}
}