문제풀이 22번

박천규·2020년 12월 29일
0

자바 기초문제풀이

목록 보기
22/30

학생수와 점수들이 순서대로 입력된다. 평균보다 넘은 학생들의 비율을 출력하시오

입력 : 7 100 95 90 80 70 60 50

정답: 57.143%

package _2;
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
	    Scanner sc = new Scanner(System.in);
	    int number = sc.nextInt();
	    int sum=0;
	    int count=0;
	    int[] score = new int[number];
	    for(int i=0; i<number ; i++) score[i] = sc.nextInt();
	    for(int i: score) {
	    	sum+=i;
	    }
	    for( int i: score) {
	    	if((sum/number) <i) count++;
	    }

	    System.out.print("평균을 넘는 학생들의 비율은 "+(count/(double)number) *100+" 입니다");
        // 소수점으로 출력하려면 나누어 지는수, 나누는 수 둘중 하나는 실수형으로 캐스팅 해야한다.!!
	    
				
	
	}
}
profile
자바 공부중

0개의 댓글

관련 채용 정보