프로그래머스 - 하샤드 수

Jongleee·2022년 7월 16일
1

알고리즘

목록 보기
12/39
class Solution {
    public boolean solution(int x) {
        int n =0;
        String[] a=Integer.toString(x).split("");
        // 숫자로 변환하여 한자리씩 더함
        for (int i = 0; i < a.length; i++) {
            n+=Integer.parseInt(a[i]);
        }
        if (x%n==0){
            return true;
        }
        else return false;

    }
}

앞서 구한 자릿수 더하기에서 한단계 추가된 문제

0개의 댓글