Created
February 2, 2014 12:26
-
-
Save gourab5139014/8767638 to your computer and use it in GitHub Desktop.
Permutations of a String by Recursion using 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
public static void permuteString(String beginningString, String endingString) { | |
if (endingString.length() <= 1) { System.out.println(beginningString + endingString); } | |
else { | |
for (int i = 0; i < endingString.length(); i++) { | |
try { | |
String newString = endingString.substring(0, i) + endingString.substring(i + 1); //current character removed from the new string | |
permuteString(beginningString + endingString.charAt(i), newString); | |
} catch (Exception e) { System.err.println(e.getMessage()); } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment