Advertisement
Guest User

Good Numbers

a guest
Nov 10th, 2022
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1.  
  2. import java.math.BigInteger;
  3. import java.util.*;
  4. import java.util.stream.Collectors;
  5.  
  6. public class test {
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9.  
  10. int num1 = Integer.parseInt(scanner.nextLine());
  11. int num2 = Integer.parseInt(scanner.nextLine());
  12. int output = 0;
  13.  
  14. for (int i = num1; i <= num2 ; i++) {
  15. int currentNum = i;
  16. String current = i + "";
  17. int counter = 0;
  18. while (currentNum != 0) {
  19. int lastDigit = currentNum % 10;
  20. if (lastDigit == 0) {
  21. counter++;
  22. currentNum = currentNum / 10;
  23. continue;
  24. }
  25. if (i % lastDigit == 0) {
  26. counter++;
  27. }
  28. currentNum = currentNum / 10;
  29. }
  30. if (counter == current.length()) {
  31. output++;
  32. }
  33. }
  34. System.out.println(output);
  35.  
  36. }
  37. }
  38.  
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement