손코딩

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

Java

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

활시현 2021. 1. 27. 16:54
728x90
728x90

import java.util.*;

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

        return answer;
    }
}