Я пытаюсь найти перестановку данной строки, но я хочу использовать итерацию. Рекурсивное решение, которое я нашел в Интернете, и я его понимаю, но преобразование его в итерационное решение действительно не работает. Ниже я прикрепил свой код. Я очень благодарен за помощь:
public static void combString(String s) {
char[] a = new char[s.length()];
//String temp = "";
for(int i = 0; i < s.length(); i++) {
a[i] = s.charAt(i);
}
for(int i = 0; i < s.length(); i++) {
String temp = "" + a[i];
for(int j = 0; j < s.length();j++) {
//int k = j;
if(i != j) {
System.out.println(j);
temp += s.substring(0,j) + s.substring(j+1,s.length());
}
}
System.out.println(temp);
}
}