fork download
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. Scanner sc = new Scanner(System.in);
  6. int A = sc.nextInt();
  7. int B = sc.nextInt();
  8. boolean found = false;
  9.  
  10. for (int i = A; i <= B; i++) {
  11. int x = i;
  12. boolean isLucky = true;
  13.  
  14. while (x > 0) {
  15. int digit = x % 10;
  16. if (digit != 4 && digit != 7) {
  17. isLucky = false;
  18. break;
  19. }
  20. x /= 10;
  21. }
  22.  
  23. if (isLucky) {
  24. if (found) System.out.print(" ");
  25. System.out.print(i);
  26. found = true;
  27. }
  28. }
  29.  
  30. if (!found) {
  31. System.out.println(-1);
  32. }
  33. sc.close();
  34. }
  35. }
  36.  
Success #stdin #stdout 0.18s 56584KB
stdin
4 20
stdout
4 7