๋ฐ์ํ
์ฝ๋
import java.util.Arrays;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int T = scan.nextInt();
for(int tc=1; tc<=T; tc++) {
int[] arr = new int[10];
long avg;
for(int i=0; i<arr.length; i++) {
arr[i] = scan.nextInt();
}
avg = Math.round(Arrays.stream(arr).average().getAsDouble());
System.out.println("#" + tc + " " + avg);
}
scan.close();
}
}
ํ์ด
Stream์ average().getAsDouble() ๋ฅผ ํตํด Double๋ก ํ๊ท ์ ๊ตฌํ๋ค.
๊ทธ ํ Math.round() ํจ์๋ฅผ ํตํด ์์์ ์ ๋ฐ์ฌ๋ฆผ ํด์ ๋ํ๋ธ๋ค.
- round() ๋ฆฌํด ์๋ฃํ: double, long
๋ฐ์ํ
'Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[SW Expert Academy] - (D1)1933. ๊ฐ๋จํ N์ ์ฝ์(Stream) (0) | 2020.08.09 |
---|---|
[SW Expert Academy] - (D1)2019. ๋๋ธ๋๋ธ(Stream) (0) | 2020.08.08 |
[SW Expert Academy] - (D1)2072. ํ์๋ง ๋ํ๊ธฐ(Stream) (4) | 2020.08.05 |
[๋ฐฑ์ค] 2562๋ฒ: ์ต๋๊ฐ(Stream) (0) | 2020.08.04 |
[SW Expert Academy] - (D3)2817. ๋ถ๋ถ ์์ด์ ํฉ (0) | 2020.07.19 |
๋๊ธ