Guest User

Untitled

a guest
Dec 9th, 2019
118
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. boolean includeNum(int n, int m)
  2. {
  3. while(m > 0)
  4. {
  5. if(n%10 == m%10)
  6. {
  7. n = n/10;
  8. m= m/10;
  9. }
  10. else
  11. return false;
  12. }
  13. return true;
  14. }
  15. int checkNumDigitsSum(int n)
  16. {
  17. int sum = 0;
  18. while(n > 0 )
  19. {
  20. sum = sum+ n%10;
  21. n=n/10;
  22. }
  23. return sum;
  24. }
  25. int MaxNumber(int n)
  26. {
  27. int saveNum = n;
  28. int counter = 0;
  29.  
  30. while(saveNum > 0)
  31. {
  32. saveNum= saveNum/10;
  33. counter++;
  34. }
  35. int checkNumber = n;
  36. int ret = 0;
  37. boolean t;
  38.  
  39. while(checkNumber%n != 0 && ret!= n && t != true )
  40. {
  41. ret=checkNumDigitsSum(checkNumber);
  42. t = includeNum(checkNumber,n);
  43. checkNumber = checkNumber+Math.pow(10,counter);
  44. }
  45.  
  46. return checkNumber;
  47.  
  48. }
RAW Paste Data