Guest User

Untitled

a guest
Jul 17th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. //Check that the number can be divided by the sum of its digit
  2. public class dividible_by_its_sum {
  3. static boolean divcheck(int n, int digit) {
  4. //if digit divides number
  5. return(digit!=0&&n%digit==0);
  6. }
  7.  
  8. static boolean allDigitsDivide(int n) {
  9. int temp = n;
  10. while(temp>0) {
  11. int digit = n % 10;
  12.  
  13. if((divcheck(n, digit))==false)
  14. return false;
  15. temp/=10;
  16. }
  17. return true;
  18. }
  19.  
  20. public static void main(String[] args) {
  21. int n = 128;
  22. if(allDigitsDivide(n))
  23. System.out.println("Yes");
  24. else
  25. System.out.println("No");
  26. }
  27. }
Add Comment
Please, Sign In to add comment