본문 바로가기
(문제풀이)

프로그래머스(java) : 짝수의 합

by cogito-new 2022. 10. 9.

class Solution {
    public int solution(int n) {
        int answer = 0;
        for(int i = 1; i<= n; i++){   
        if( i%2 == 0){
            answer += i;        
            }
        }
        return answer;
    }
}

 

반응형