How to create a recursive method that could find permutations of a string? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How to create a recursive method that could find permutations of a string?

For example: String str = “ABC”; After execute the recursive method in main(), the output will be something like this: Public static void main(String a[]) { System.out.println(permutations(“ABC”); } => output: ABC ACB BCA BAC CAB CBA Thanks for reading!! ❤️

15th Nov 2018, 1:48 AM
Quang Tran
Quang Tran - avatar
5 Answers
+ 4
Recursion is calling the same function after with itself. A visual example is two mirrors facing each other. The key is when to break...
16th Nov 2018, 11:10 PM
Da2
Da2 - avatar
+ 3
Recursion is very trick, one has to be fairly skilled in working with loops before leaping into it. I advise that you start with very simple loops and try to implement the same function using recursion...
15th Nov 2018, 8:49 AM
Da2
Da2 - avatar
+ 1
Is the above permutation restricted to three characters? Or from 1 to 3 characters
16th Nov 2018, 3:49 AM
Codeblooded(Ani Daniel C)
Codeblooded(Ani Daniel C) - avatar
+ 1
Da2 I’m pretty comfortable with loop. I just can’t figure out the algorithm to produce the required output (yet)
16th Nov 2018, 6:36 AM
Quang Tran
Quang Tran - avatar
0
Ani Daniel No, it suppose to work with any string input (but let say the input only have 3-5 characters)
16th Nov 2018, 6:33 AM
Quang Tran
Quang Tran - avatar