import java.io.*;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = Integer.parseInt(br.readLine());
for (int t = 0; t < n; t++) {
//Stream을 이용하여 String[]을 int[]로 변환하는 방법
int[] list = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
int num = list[0];
int[] score = Arrays.copyOfRange(list, 1, list.length);
//Stream을 이용하여 int배열 내 숫자의 총 합을 내는 방법
double avg = Arrays.stream(score).sum() / num;
//Stream을 이용하여 int배열 내 숫자들 중 조건에 맞는 숫자들 개수 구하는 방법
double count = Arrays.stream(score).filter(number -> number > avg).count();
bw.write(String.format("%.3f", count / num * 100) + "%\n");
}
bw.flush();
bw.close();
}
}
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = Integer.parseInt(br.readLine());
for (int t = 0; t < n; t++) {
String[] temp = br.readLine().split(" ");
int num = Integer.parseInt(temp[0]);
int[] score = new int[num];
int sum = 0;
for (int i = 1; i < temp.length; i++) {
score[i-1] = Integer.parseInt(temp[i]);
sum += score[i-1];
}
double avg = sum / num;
int count = 0;
for (int i = 0; i < score.length; i++) {
if (score[i] > avg) count++;
}
bw.write(String.format("%.3f", (double) count / num * 100) + "%\n");
}
bw.flush();
bw.close();
}
}
Stream을 처음 써보는데, 생각보다 너무 편해서 좋았음
Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
Arrays.stream(score).sum() / num;
Arrays.stream(score).filter(number -> number > avg).count();