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

 

주의 number % (n+m) 하면 안된다.

class Solution {
    public int solution(int number, int n, int m) {
        return number % n == 0 && number % m == 0 ? 1 : 0;
    }
}

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

조건 문자열  (0) 2024.01.23
홀짝에 따라 다른 값 반환하기  (0) 2024.01.23
n의 배수  (0) 2024.01.23
두 수의 연산값 비교하기  (0) 2024.01.23
더 크게 합치기  (0) 2024.01.23

 

class Solution {
    public int solution(int num, int n) {
        return num % n == 0 ? 1 : 0;
    }
}

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

홀짝에 따라 다른 값 반환하기  (0) 2024.01.23
공배수  (1) 2024.01.23
두 수의 연산값 비교하기  (0) 2024.01.23
더 크게 합치기  (0) 2024.01.23
문자열 곱하기  (0) 2023.07.06

 

class Solution {
    public int solution(int a, int b) {
        int plus = Integer.parseInt("" + a + b);
        int gob = 2 * a * b;
        return plus >= gob ? plus : gob;
    }
}

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

공배수  (1) 2024.01.23
n의 배수  (0) 2024.01.23
더 크게 합치기  (0) 2024.01.23
문자열 곱하기  (0) 2023.07.06
문자 리스트를 문자열로 변환하기  (0) 2023.07.06

+ Recent posts