Question: Write a recursive method to print all the permutations of a string. For example, for the string abc, the permuation is abc acb bac bca
Write a recursive method to print all the permutations of a string. For example, for the string abc, the permuation is
abc
acb
bac
bca
cab
cba
public static void displayPermutation(String s)
public static void displayPermutation(String s1, String s2)
The first method simply invokes displayPermutation(" ", s). The second method uses a loop to move a character from s2 to s1 and recursively invokes it with a new s1 and s2. The base case is that s2 is empty and prints s1 to the console.
Step by Step Solution
3.26 Rating (167 Votes )
There are 3 Steps involved in it
Program plan Create display Permutation St ring method to call displayPermutation String String meth... View full answer
Get step-by-step solutions from verified subject matter experts
