Вот мой более компактный вариант, с выводом как в книге:
public class App {
private static final Integer START_NUM = 1000;
private static final Integer END_NUM = 9999;
private static final String ANSWER = "%d = %s * %s\n";
public static void main(String[] args) {
for (int num = START_NUM; num < END_NUM; num++) {
List<Integer> firstComb = new ArrayList<>();
List<Integer> secondComb = new ArrayList<>();
char[] number = String.valueOf(num).toCharArray();
for (int firstChar = 0; firstChar < 4; firstChar++) {
for (int secondChar = firstChar + 1; secondChar < 4; secondChar++) {
String firstHalf = "" + number[firstChar] + number[secondChar];
String secondHalf = "" + number[secondChar] + number[firstChar];
firstComb.add(Integer.valueOf(firstHalf));
secondComb.add(Integer.valueOf(secondHalf));
}
}
for (int i = 0, j = 5; i < firstComb.size(); i++, j--) {
if ((firstComb.get(i) * secondComb.get(j)) == num) {
System.out.printf(ANSWER, num, secondComb.get(j), firstComb.get(i));
break;
} else if ((firstComb.get(i) * firstComb.get(j)) == num) {
System.out.printf(ANSWER, num, firstComb.get(j), firstComb.get(i));
break;
} else if ((secondComb.get(i) * secondComb.get(j)) == num) {
System.out.printf(ANSWER, num, secondComb.get(j), secondComb.get(i));
break;
}
}
}
}
}
Возможно вам не актуально, но кому-то это точно поможет