import java.util.Scanner; public class GoodNumbers { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); //Read the input split by space, convert it to String Array String input = scanner.nextLine(); String[] inputArr = input.split("\\s"); int firstInt = Integer.parseInt(inputArr[0]); int finalInt = Integer.parseInt(inputArr[1]); int totalGoodCount = 0; for (int number = firstInt; number <= finalInt; number++) { //Create a char array that will hold the digits of the generated number //Integer.toString(idx).toCharArray(); - converts number to string to char array char[] charArray = Integer.toString(number).toCharArray(); int count = 0; //Loop through the char array for (int k = 0; k < charArray.length; k++) { //get the int value of the character j int j = Character.getNumericValue(charArray[k]); // and check if the whole number can be divided by each of its digits if (j == 0 || (number % j) == 0) { //if yes, the number is divisible by j and count is incremented by 1 count++; } } //if count of digits that are divisible equals char array length //this means that the number is good if (count == charArray.length) { System.out.printf("%d good\n", number); totalGoodCount++; } else { System.out.printf("%d not good\n", number); } } System.out.println(totalGoodCount); } }