본문 바로가기
CodingTest/프로그래머스

[JAVA] 프로그래머스 Lv1 - 약수의 합

by JJH0100 2023. 4. 13.
728x90
반응형

 

풀이방법

가장 일반적인 방법으로 풀었다.

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

728x90
반응형

댓글