Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions