Advertisement
Guest User

Good Numbers

a guest
Apr 1st, 2022
55
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Task5_GoodNumbers {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. String line = scanner.nextLine();
  8. String[] input = line.split(" ");
  9.  
  10. int firstNum = Integer.parseInt(input[0]);
  11. int secondNum = Integer.parseInt(input[1]);
  12.  
  13. int counter = 0;
  14. boolean isGoodNumber = true;
  15. String s = "";
  16.  
  17. for (int i = firstNum; i <= secondNum; i++) {
  18. s = Integer.toString(i);
  19. for (int j = 0; j < s.length(); j++) {
  20. if (s.charAt(j) - '0' == 0) {
  21. continue;
  22. }
  23. if (i % (s.charAt(j) - '0') != 0) {
  24. isGoodNumber = false;
  25. break;
  26. }
  27. }
  28. if (isGoodNumber) {
  29. counter += 1;
  30. }
  31. isGoodNumber = true;
  32. }
  33. System.out.println(counter);
  34. }
  35. }
Advertisement
RAW Paste Data Copied
Advertisement