본문 바로가기
ONLINE JUDGE/배열

[백준4344] 평균은 넘겠지

by W_W_Woody 2022. 3. 1.

https://www.acmicpc.net/problem/4344

 

4344번: 평균은 넘겠지

대학생 새내기들의 90%는 자신이 반에서 평균은 넘는다고 생각한다. 당신은 그들에게 슬픈 진실을 알려줘야 한다.

www.acmicpc.net


package s05_array;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class MJ_07_4344_3 {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int[] array;
		int C = Integer.parseInt(br.readLine());
		StringTokenizer st;
		
		for(int i=0;i<C;i++) {
			st = new StringTokenizer(br.readLine()," ");
			int N = Integer.parseInt(st.nextToken());
			array = new int[N];

			double sum = 0;//*
			
			for(int j=0;j<N;j++) {
				int su = Integer.parseInt(st.nextToken());
				array[j]=su;
				sum += su;
			}
			double avg = (sum/N);//*
			double count = 0;//*

			//*평균넘는 학생찾기
			for(int j=0;j<N;j++) {
				if(array[j]>avg) {
					count++; //*
				}
			}
            
			System.out.printf("%.3f%%\n",(count/N)*100);//*
		}
	}
}

[Java] 💻printf 출력문

 

[Java] 💻printf 출력문

System.out.printf ( 포맷문자, 데이터 ); 데이터의 종류를 표시할 수 있는 포맷 문자를 지원하는 출력문이다. ("%d", 정수) System.out.printf("%d\n",60); System.out.printf("%,d\n",60000);//3자리 단위로 쉼..

world-wide-woody.tistory.com

%기호 출력 시 앞에 % 붙이기

'ONLINE JUDGE > 배열' 카테고리의 다른 글

[백준8958] OX퀴즈  (0) 2022.02.25
[백준1546] 평균  (0) 2022.02.24
[백준3052] 나머지  (0) 2022.02.23
[백준2562] 최댓값 다시보기  (0) 2022.02.10
[백준10818] 최소, 최대  (0) 2022.02.09

댓글