Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package L06_NestedLoops;
- import java.util.Scanner;
- public class P05_SpecialNumbers {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int number = Integer.parseInt(scanner.nextLine());
- //for -> 1111 до 9999 -> проверяваме дали конкретното число е специално
- for (int i = 1111; i <= 9999 ; i++) {
- //намираме всяка една цифра
- int firstDigit = i / 1000;
- int secondDigit = i / 100 % 10;
- int thirdDigit = i / 10 % 10;
- int fourthDigit = i % 10;
- // проверяваме дали числото е специално
- boolean checkFirst = number % firstDigit == 0;
- boolean checkSecond = secondDigit != 0 && number % secondDigit == 0;
- boolean checkThird = thirdDigit != 0 && number % thirdDigit == 0;
- boolean checkFourth = fourthDigit != 0 && number % fourthDigit == 0;
- //проверяваме дали имаме 4 пъти true
- if(checkFirst && checkSecond && checkThird && checkFourth){
- System.out.printf("%d ", i);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement