본문 바로가기
알고리즘/프로그래머스 1단계

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

by lanuarius19 2022. 4. 23.
728x90

프로그래머스 1단계
자릿수 더하기

https://programmers.co.kr/learn/challenges

 

문제 설명

자릿수 더하기

 

 

 

풀이

 

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

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

        return answer;
    }
}
 
728x90

댓글