슈콩

[프로그래머스] 자릿수 더하기 본문

Algorithms/Programmers

[프로그래머스] 자릿수 더하기

shukong 2025. 10. 23. 23:48

 

[문제]

https://school.programmers.co.kr/learn/courses/30/lessons/12931

 

프로그래머스

SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

 

 

 

[소스 코드]

import java.util.*;

public class Solution {
    public int solution(int n) {
        int answer = 0;

        while(n>0){
            answer += n % 10 ;
            n /= 10;
        }
        return answer;
    }
}