[프로그래머스]평균 구하기

mongs_Develop·2022년 4월 26일
0

Programmers-Level1-Java

목록 보기
6/30
post-thumbnail
  • 문제 & 예시

  • 소스코드

// 평균 구하기
public class test06 {

	public static void main(String[] args) {
		Solution6 sol = new Solution6();
		int[] arr = {1, 2, 3, 4};
		System.out.println(sol.solution(arr));
	}

}

class Solution6 {
    public double solution(int[] arr) {
        double answer = 0;
        int sum = 0;
        
        for(int i = 0;i<arr.length;i++) {
        	sum += arr[i];
        }
        answer = (double)sum / arr.length;
        return answer;
    }
}
  • consol
profile
개 발 인생

0개의 댓글