Advertisement
mirozspace

Pr_sp_number_v2

Apr 17th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SpecialNumber {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.         int n = Integer.parseInt(scanner.nextLine());
  8.  
  9.         boolean isSpecial = false;
  10.         for (int i = 1111; i <= 9999; i++) {
  11.             int digit = i;
  12.             int digitForPrint = digit;
  13.             while (digit > 0) {
  14.                 int number = digit % 10;
  15.                 if (number == 0) {
  16.                     isSpecial = false;
  17.                     break;
  18.                 }
  19.                 if (n % number == 0) {
  20.                     isSpecial = true;
  21.                 } else {
  22.                     isSpecial = false;
  23.                     break;
  24.                 }
  25.                 digit = digit / 10;
  26.             }
  27.             if (isSpecial) {
  28.                 System.out.print(digitForPrint + " ");
  29.             }
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement