[프로그래머스] 코딩테스트 연습 - 연습문제 Level 1 자릿수 더하기

uoahy·2021년 9월 27일
0

Solution.java

import java.util.*;

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

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

        return answer;
    }
}

출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges

0개의 댓글