문제

quiz

  • 평균 경제성장률 구하기




코드

Main.java

package pack_CusCls08;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		System.out.println("10년간의 경제 성장률을 입력하세요 : ");
		double[] num = new double[10];
		double total = 0.0;
	
		
		for (int i = 0; i < num.length; i++) {
			num[i] = scanner.nextDouble();
			total += num[i];
		}
		scanner.close();
		
		CustomCls customCls = new CustomCls(num, total);
		customCls.mtdGrowth();

	}

}

CustomCls.java

package pack_CusCls08;

public class CustomCls {
	
	private double[] num;
	private double total;

	public CustomCls(double[] num, double total) {
		this.num = num;
		this.total = total;
	}
	
	public void mtdGrowth() {
		int count = 0;
		
		double res = total / 10;
		
		System.out.printf("평균 경제성장률 : %.2f", res);
		System.out.println();
		
		for (int i = 0; i < num.length; i++) {
			if (num[i] > res) {
				count++;
			}
		}
		System.out.printf("평균 경제성장률을 초과한 횟수 : %d", count);		
	}

}


결과

quiz

Leave a comment