Advertisement
deyanivanov966

06. Special Numbers

Apr 5th, 2021
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.15 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class demo {
  3.     public static void main(String[] args) {
  4.         Scanner scanner = new Scanner(System.in);
  5.         int n = Integer.parseInt(scanner.nextLine());
  6.         //всички числа от 1111 до 9999
  7.         for (int firstDigit = 1; firstDigit <= 9 ; firstDigit++) {
  8.             for (int secondDigit = 1; secondDigit <= 9 ; secondDigit++) {
  9.                 for (int thirdDigit = 1; thirdDigit <= 9 ; thirdDigit++) {
  10.                     for (int forthDigit = 1; forthDigit <= 9 ; forthDigit++) {
  11.                         //генерирано четирицифрено число
  12.                         boolean check1 = n % firstDigit == 0;
  13.                         boolean check2 = n % secondDigit == 0;
  14.                         boolean check3 = n % thirdDigit == 0;
  15.                         boolean check4 = n % forthDigit == 0;
  16.                         if (check1 && check2 && check3 && check4) {
  17.                             System.out.printf("%d%d%d%d ", firstDigit, secondDigit, thirdDigit, forthDigit);
  18.                         }
  19.                     }
  20.                 }
  21.             }
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement