Published:
Updated:

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


Solution

import java.util.*;

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

        while (true) {
            answer += n % 10;
            n /= 10;

            if (n == 0) {
                break;
            }
        }
        return answer;
    }

    public static void main(String[] args) {
        System.out.println(solution(123));
    }
}

Leave a comment