Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Check that the number can be divided by the sum of its digit
- public class dividible_by_its_sum {
- static boolean divcheck(int n, int digit) {
- //if digit divides number
- return(digit!=0&&n%digit==0);
- }
- static boolean allDigitsDivide(int n) {
- int temp = n;
- while(temp>0) {
- int digit = n % 10;
- if((divcheck(n, digit))==false)
- return false;
- temp/=10;
- }
- return true;
- }
- public static void main(String[] args) {
- int n = 128;
- if(allDigitsDivide(n))
- System.out.println("Yes");
- else
- System.out.println("No");
- }
- }
Add Comment
Please, Sign In to add comment