[프로그래머스 문제풀이53]자릿수 더하기 자바

이ᄏᄋ·2021년 9월 29일
0
import java.util.*;

public class Solution {
    public int solution(int n) {
        int answer = 0;
        String to = Integer.toString(n);
       
        char[] toArray=to.toCharArray();
        for(int i=0;i<toArray.length;i++){
            answer+=toArray[i]-'0';
        }
       

        return answer;
    }
}

오랜만에 자바로 풀었는데
js가 확실히 편하긴함

profile
미쳤다.

0개의 댓글