myrdok123

P05SpecialNumbers

Feb 12th, 2023
1,022
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. package NestedLoops.Exercises;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class P05SpecialNumbers {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         int number = Integer.parseInt(scanner.nextLine());
  11.  
  12.         for (int currentNum = 1111; currentNum <= 9999 ; currentNum++) {
  13.  
  14.             int first = currentNum / 1000;
  15.             int second = currentNum / 100 % 10;
  16.             int third = currentNum / 10 % 10;
  17.             int fourth = currentNum % 10;
  18.  
  19.  
  20.             boolean checkFirstDigit = number % first == 0;
  21.             boolean checkSecondDigit = second != 0 && number % second == 0;
  22.             boolean checkThirdDigit = third != 0 && number % third == 0;
  23.             boolean checkFourthDigit = fourth != 0 && number % fourth == 0;
  24.  
  25.             if (checkFirstDigit && checkSecondDigit && checkThirdDigit && checkFourthDigit){
  26.                 System.out.printf("%d ", currentNum);
  27.             }
  28.  
  29.  
  30.  
  31.         }
  32.     }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment