Question: IN JAVA: Write a recursive method to print all the permutations of any string. For example, for the string abc: abc acb bac bca cab

IN JAVA:

Write a recursive method to print all the permutations of any string. For example, for the string abc:

abc

acb

bac

bca

cab

cba

using following two methods:

public static void displayPermutations (String s)

public static void displayPermutations (String s1, String s2) //helper

Note: Helper 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 print s1 to the console.

Here is the given code with a Driver Class, DO NOT MODIFY THE CODE

import java.util.*;

import java.lang.*;

import java.io.*;

class HW4_P1{

public static void displayPermuation(String s) {

displayPermutation("",s);

}

public static void displayPermuation(String s1, String s2) {

}

}

class DriverMain{

public static void main(String args[]){

Scanner input = new Scanner(System.in);

HW4_P1.displayPermuation(input.nextLine());

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!