프로그래머스

프로그래머스(JAVA) / 짝수의 합

bokboks 2023. 3. 18. 00:19


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