Created
December 30, 2013 21:55
-
-
Save pandey-adarsh147/8188884 to your computer and use it in GitHub Desktop.
Generate all permutation of a string
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 class GenerateAllPermutation { | |
public static void main(String... arg) { | |
Scanner scanner = new Scanner(System.in); | |
String sequence = scanner.nextLine(); | |
generatePermutation("", sequence); | |
} | |
private static void generatePermutation(String prefix, String sequence) { | |
if(sequence.length() == 0) System.out.println(prefix); | |
for (int i = 0; i < sequence.length(); i++) { | |
generatePermutation(prefix + sequence.charAt(i), sequence.substring(0, i) + sequence.substring(i+1)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment