알고리즘
[Java] SWEA - 평균값 구하기
J3SUNG
2023. 1. 12. 20:58
728x90
평균값을 구하는 문제입니다.
받은 값들을 전부 더해서 개수만큼 나눠줍니다.
import java.util.Scanner;
import java.io.FileInputStream;
class Solution
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int T;
T=sc.nextInt();
for(int test_case = 1; test_case <= T; test_case++)
{
double sum = 0;
double avg;
int ans;
for(int i=0; i<10; ++i){
sum += sc.nextInt();
}
avg = Math.round(sum/10);
ans = (int)avg;
System.out.printf("#%d %d\n",test_case, ans);
}
}
}