https://programmers.co.kr/learn/courses/30/lessons/12944

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - ํ‰๊ท  ๊ตฌํ•˜๊ธฐ | ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

์ •์ˆ˜๋ฅผ ๋‹ด๊ณ  ์žˆ๋Š” ๋ฐฐ์—ด arr์˜ ํ‰๊ท ๊ฐ’์„ returnํ•˜๋Š” ํ•จ์ˆ˜, solution์„ ์™„์„ฑํ•ด๋ณด์„ธ์š”. ์ œํ•œ์‚ฌํ•ญ arr์€ ๊ธธ์ด 1 ์ด์ƒ, 100 ์ดํ•˜์ธ ๋ฐฐ์—ด์ž…๋‹ˆ๋‹ค. arr์˜ ์›์†Œ๋Š” -10,000 ์ด์ƒ 10,000 ์ดํ•˜์ธ ์ •์ˆ˜์ž…๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ arr return [1,2,3,4] 2.5 [5,5] 5

programmers.co.kr

 

ํ‰๊ท ๊ตฌํ•˜๊ธฐ ๋ฌธ์ œ

 

 

โ—‹ ์ฒ˜์Œ ํ‘ผ ํ’€์ด

1
2
3
4
5
6
7
8
9
10
class Solution {
  public double solution(int[] arr) {
      double answer = 0;
      for(int i=0; i<arr.length;i++){
          answer+=arr[i];
      }
      answer/=arr.length;
      return answer;
  }
}
cs

+ Recent posts