[프로그래머스 문제풀이62]하샤드 수 자바

이ᄏᄋ·2021년 9월 30일
0
class Solution {
    public boolean solution(int x) {
        boolean answer = false;
        char[] xStr=Integer.toString(x).toCharArray();
        int sum=0;
        for(int i=0;i<xStr.length;i++){
            sum+=xStr[i]-'0';
        }
        if(x%sum==0){
            answer=true;
        }
        return answer;
    }
}
profile
미쳤다.

0개의 댓글