개발하는 자몽

[1546] 1차원 배열 - 평균 본문

Algorithm

[1546] 1차원 배열 - 평균

jaamong 2022. 3. 31. 14:14

문제

 

코드

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.Arrays;

public class Main{
    public static void main(String[] args) throws IOException {
       
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        double arr[] = new double[Integer.parseInt(br.readLine())];
        
        StringTokenizer st = new StringTokenizer(br.readLine(), " ");
        
        for(int i=0; i<arr.length; i++){
            arr[i] = Double.parseDouble(st.nextToken());
        }
        
        double sum=0;
        Arrays.sort(arr);
        for(int i=0; i<arr.length; i++){
            sum += arr[i]/arr[arr.length-1] * 100;
        }
        System.out.println(sum/arr.length);
    }
}
Comments