th42500의 TIL

[Java] SWEA2071 - 평균값구하기 본문

Algorithm/SWEA

[Java] SWEA2071 - 평균값구하기

th42500 2021. 12. 16. 17:29

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

 

SW Expert Academy

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

swexpertacademy.com

 

💡 포인트

1️⃣ 테스트케이스 T만큼 반복해서 답 출력

2️⃣ 답은 소수점 첫째 자리에서 반올림한 정수 👉 Math.round(반올림 적용할 수) 이용

3️⃣ 테스트케이스는 1부터 시작

✔ 소스코드

import java.util.Scanner;

public class Solution {  // 2071.평균값 구하기

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int T = sc.nextInt();
		
		for (int t = 1; t <= T; t++) {
			
			int sum = 0;
			
			for (int i = 0; i < 10; i++) {
				int num = sc.nextInt();
				sum += num;
			}

			System.out.println("#" + t + " " + Math.round(sum/10.0));
		}
	}

}
Comments