forked from mouredev/retos-programacion-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5d151a
commit b497ff6
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
Retos/Reto #36 - PERMUTACIONES [Media]/java/AnNavNicolas.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
public class AnNavNicolas { | ||
public static void main(String[] args) { | ||
|
||
String text = "sol"; | ||
permutar(text, ""); | ||
|
||
} | ||
|
||
public static void permutar(String text, String response) { | ||
|
||
if (text.isBlank() || text.length() < 1) { | ||
System.out.println(response); | ||
return; | ||
} | ||
|
||
for (int i = 0; i < text.length(); i++) { | ||
String current_letter = String.valueOf(text.charAt(i)); | ||
String left = text.substring(0, i); | ||
String rigth = text.substring(i + 1); | ||
permutar(left + rigth, response + current_letter); | ||
} | ||
} | ||
} |