본문 바로가기

Coding Test/프로그래머스

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

class Solution{
    public int solution(int n) {
        int answer = 0;
        while (n > 0) {
            answer += n % 10;
            n /= 10;
        }
        return answer;
    }
}