본문 바로가기

Java/SWEA

[JAVA] SWEA 1984. 중간 평균값 구하기

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=2&contestProbId=AV5Pw_-KAdcDFAUq&categoryId=AV5Pw_-KAdcDFAUq&categoryType=CODE&problemTitle=&orderBy=FIRST_REG_DATETIME&selectCodeLang=JAVA&select-1=2&pageSize=10&pageIndex=1

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

 

정답 

 

import java.util.Scanner;
import java.util.Arrays;
 
class Solution
{
    public static void main(String args[]) throws Exception
    {   
        Scanner sc = new Scanner(System.in);
         
        int T = sc.nextInt();
         
        for(int t=1; t<=T; t++)
        {
            int answer =0;
             
            int num[] = new int[10];
             
            for(int i=0; i<10; i++)
            {
                num[i] = sc.nextInt();
            }
             
            Arrays.sort(num);
             
            int newArr[] = Arrays.copyOfRange(num,1,9);
             
            int sum = 0;
            for(int i=0; i<newArr.length; i++)
            {
                sum+=newArr[i];
            }
             
            answer = (int)Math.round((double)sum/newArr.length);
 
            System.out.printf("#%d %d\n",t,answer);
        }
    }
}