class Solution {
    public int solution(int n) {
        int result = 0;
        if(n % 2 == 0){
            for(int i=0; i<=n; i++){
                if(i % 2 == 0){
                    result += (i*i);
                }
            }
        }
        else{
            for(int i=0; i<=n; i++){
                if(i % 2 != 0 ){
                    result += i;
                }   
            }
        }
        return result;
    }
}

'공부 > 프로그래머스' 카테고리의 다른 글

flag에 따라 다른 값 반환하기  (0) 2024.01.23
조건 문자열  (0) 2024.01.23
공배수  (1) 2024.01.23
n의 배수  (0) 2024.01.23
두 수의 연산값 비교하기  (0) 2024.01.23

+ Recent posts