📖Algorithm/Simulation, Math
자바 [Programmers] 1단계 - 하샤드 수
구동엽
2024. 2. 18. 01:41
class Solution {
public boolean solution(int x) {
boolean answer = true;
int new_x = 0;
int xx = x;
while(xx > 0){
new_x += xx%10;
xx/=10;
}
if(x % new_x == 0){
return true;
}else{
return false;
}
}
}
이 문제는 자리수의 합만 구하면 쉽게 풀 수 있는 문제이다.
앞에서 풀어봤으니 쉽게 풀 수 있었다.