Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class GoodNumbes {
  4.  
  5. public static int checkDigits(int a, int b){
  6.  
  7. boolean isGood = true;
  8. int counterNum = 0;
  9.  
  10. for (int i = b; i >= a; i--) {
  11.  
  12.  
  13. if (a <= 10 && b <= 10) {
  14. counterNum++;
  15. } else {
  16. isGood = true;
  17.  
  18. int counter = 0;
  19. int[] arr = new int[10];
  20. int copy = i;
  21. while (copy > 0) {
  22. int digit = copy % 10;
  23. arr[counter] = digit;
  24. counter++;
  25. if (!(copy > 10)) {
  26. break;
  27. }
  28. else{
  29. copy /= 10;
  30. }
  31.  
  32.  
  33. }
  34. for (int j = 0; j < counter; j++) {
  35.  
  36. if (arr[j] == 0) {
  37. continue;
  38. }
  39. if (i % arr[j] != 0) {
  40. isGood = false;
  41. break;
  42.  
  43.  
  44. }
  45.  
  46. }
  47. if (isGood) {
  48.  
  49. counterNum++;
  50. }
  51. isGood = true;
  52. }
  53. }
  54. System.out.println();
  55. return (counterNum);
  56.  
  57. }
  58.  
  59. public static void main(String[] args) {
  60.  
  61.  
  62. Scanner in = new Scanner(System.in);
  63. String line = in.nextLine();
  64.  
  65. String[] nums = line.split(" ");
  66. int[] arr = new int[2];
  67.  
  68.  
  69. for (int i = 0; i < arr.length ; i++) {
  70. arr[i] =Integer.parseInt(nums[i]);
  71. }
  72.  
  73. int a = arr[0];
  74. int b = arr[1];
  75.  
  76.  
  77. System.out.println(checkDigits(a, b));
  78.  
  79.  
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement