개발자/프로그래머스

자바_프로그래머스_하샤드 수

푸루닉 2022. 11. 23. 14:21

https://github.com/pulunick/programmers-and-baekjun/blob/main/Quiz12947.java

 

GitHub - pulunick/programmers-and-baekjun

Contribute to pulunick/programmers-and-baekjun development by creating an account on GitHub.

github.com

package programmers;

public class Quiz12947 {
	public static void main(String[] args) {
		int s = 10;
		Solution3 sdf = new Solution3();
		
		System.out.println(sdf.solution3(s));
	}
	
	static class Solution3 {
	    public boolean solution3(int x) {
	        int a = 0;
	        int xd = x;
	        while(xd > 0) {
	        	a += xd%10;
	        	xd = xd/10;
	        }
	        System.out.println(a);
	        if(x%a == 0) {
	        	return true;
	        } else return false;
	    }
	}

}

 

큰 어려움이 없었고 + 노알고리즘이라 그냥 올리겠습니다.