알고리즘/백준 알고리즘
(JAVA) 백준 알고리즘 1546 문제 - 평균 구하기
Love of fate
2020. 10. 6. 09:28
728x90
반응형
(48분)
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
|
import java.util.Scanner;
public class MainTest1546 {
public static void main(String[] args) {
//평균 구하기
Scanner sc = new Scanner(System.in);
int su = sc.nextInt();
float [] suArr = new float [su];
float max = sc.nextInt();
suArr[0] = max;
for(int i = 1; i < su; i++) {
suArr[i] = sc.nextInt();
if(max < suArr[i]) {
max = suArr[i];
}
}
float sum =0;
for(int j = 0; j < suArr.length; j++) {
suArr[j] = ((float)suArr[j]/max)*100;
sum += suArr[j];
}
float avg = sum/suArr.length;
System.out.println(avg);
}
}
|
728x90
반응형