Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. public class SelfDivisorSkel
  2. {
  3.  
  4.  
  5.  
  6. public static boolean isSelfDivisor(int number)
  7. {
  8. int digit = 0;
  9. int temp = number;
  10. while (temp > 0)
  11. {
  12. digit = temp % 10;
  13. if (digit == 0 || number % digit != 0)
  14. {
  15. return false;
  16. }
  17. temp /= 10;
  18. }
  19. return true ;
  20. }
  21.  
  22. public static int[] firstNumSelfDivisor(int start, int num)
  23. {
  24.  
  25. int[] divisorArr = new int[num];
  26. for (int i = 0; i < divisorArr.length; i++)
  27. {
  28. while (!(isSelfDivisor(start)))
  29. {
  30. start++;
  31. }
  32. divisorArr[i] = start;
  33. start++;
  34. }
  35. return divisorArr;
  36. }
  37.  
  38. public static void main(String[]args)
  39. {
  40. System.out.println(isSelfDivisor(12)); //true
  41. System.out.println(isSelfDivisor(10)); //false
  42. System.out.println(isSelfDivisor(24)); //true
  43. System.out.println(isSelfDivisor(13)); //false
  44.  
  45. //part b
  46. System.out.println(firstNumSelfDivisor(10,5)); //represents and array (object), will not print the 3 values you hoped for...will print object reference.
  47.  
  48.  
  49.  
  50. System.out.print("Array values: ");
  51.  
  52. //part b
  53. for(int i = 0; i < firstNumSelfDivisor(10,5).length; i++)
  54. {
  55. System.out.print(firstNumSelfDivisor(10,5)[i] + " ");
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement