본문 바로가기
Java

java- 입력받은 숫자의 평균구하기

by zenna 2022. 1. 24.
728x90
package Java_Basic;

import java.util.Scanner;

public class Prac3 {

	public static void main(String[] args) {
		int[] fivearry = new int[5];
		Scanner input = new Scanner(System.in);
		double sum = 0;
		for (int i = 0; i < fivearry.length; i++) {
			fivearry[i] = input.nextInt();
			sum += fivearry[i];
		}
		System.out.println("평균은" + sum / fivearry.length + "입니다");
	}

}
728x90

댓글