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

mongs_Develop·2022년 5월 6일
0

Programmers-Level1-Java

목록 보기
16/30
post-thumbnail
  • 문제 & 예시

  • 소스코드

// 약수의 합
public class test16 {
	public static void main(String[] args) {
		Solution16 sol = new Solution16();
		int n = 12;
		System.out.println(sol.solution(n));
	}
}
class Solution16 {
    public int solution(int n) {
        int answer = 0;
        
        for(int i=1;i<=n;i++) {
        	if(n % i == 0) {
        		answer += i;
        	}
        }
        return answer;
    }
}
  • consol
profile
개 발 인생

0개의 댓글