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

parkkhee·2023년 3월 7일
0

Level1

목록 보기
1/23
import java.util.*;

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

        str = String.valueOf(n);
        for (int i = 0; i < str.length(); i++) {
            int num;
            num = str.charAt(i) - '0';
            answer+=num;
        }
        

        return answer;
    }
}
profile
순우리말 백엔드 개발자

0개의 댓글