Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Task5_GoodNumbers {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String line = scanner.nextLine();
- String[] input = line.split(" ");
- int firstNum = Integer.parseInt(input[0]);
- int secondNum = Integer.parseInt(input[1]);
- int counter = 0;
- boolean isGoodNumber = true;
- String s = "";
- for (int i = firstNum; i <= secondNum; i++) {
- s = Integer.toString(i);
- for (int j = 0; j < s.length(); j++) {
- if (s.charAt(j) - '0' == 0) {
- continue;
- }
- if (i % (s.charAt(j) - '0') != 0) {
- isGoodNumber = false;
- break;
- }
- }
- if (isGoodNumber) {
- counter += 1;
- }
- isGoodNumber = true;
- }
- System.out.println(counter);
- }
- }
Advertisement
RAW Paste Data
Copied
Advertisement