[JAVA 문제 풀이] 228. 하샤드 수

프로그래머스 (12947)
Stupefyee's avatar
Apr 28, 2025
[JAVA 문제 풀이] 228. 하샤드 수
notion image
 

내가 작성한 코드

class Solution { public boolean solution(int x) { int sum = 0; int temp = x; while (temp > 0) { sum += temp % 10; temp /= 10; } return x % sum == 0; } }
 

다른 사람의 코드

class Solution { public boolean solution(int x) { int sum = String.valueOf(x).chars().map(ch -> ch - '0').sum(); return x % sum == 0; } }
 
Share article

stupefyee