Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class demo {
- public static void main(String[] args) {
- Scanner scanner = new Scanner (System.in);
- int n = Integer.parseInt(scanner.nextLine());
- //1111 до 9999
- for (int number = 1111; number <= 9999 ; number++) {
- //печатаме само специални
- //1. взимаме всички цифри
- //2148
- int units = number % 10; //2148 % 10 = 8
- int tens = number / 10 % 10; // 2148 / 10 = 214 % 10 = 4
- int hundreds = number / 100 % 10; //2148 / 100 = 21 % 10 = 1
- int thousands = number / 1000; //2148 / 1000 = 2
- //n да се дели на единиците
- boolean checkUnits = units != 0 && n % units == 0;
- //n да се дели на десетиците
- boolean checkTens = tens != 0 && n % tens == 0;
- //n да се дели на стотиците
- boolean checkHundreds = hundreds != 0 && n % hundreds == 0;
- //n да се дели на хилядните
- boolean checkThousands = n % thousands == 0;
- if (checkUnits && checkTens && checkHundreds && checkThousands) {
- System.out.print(number + " ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment