Advertisement
desislava_topuzakova

06. Special Numbers

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