728x90
class Solution {
public boolean solution(int x) {
boolean answer = true;
int y = x;
int sum = 0;
while(x > 0) {
sum += x % 10;
x /= 10;
}
answer = y % sum == 0 ? true : false;
return answer;
}
}
728x90
반응형
'Algorithm > 프로그래머스' 카테고리의 다른 글
[알고리즘] 콜라츠 추측 Java (0) | 2023.11.23 |
---|---|
[알고리즘] 콜라츠 추측 Java (0) | 2023.11.01 |
[알고리즘] 문자열 내 p와 y의 개수 Java (0) | 2023.09.24 |
[알고리즘] 자릿수 더하기 Java (0) | 2023.09.18 |
[알고리즘] 숨어있는 숫자의 덧셈 (2) Java (0) | 2023.09.03 |