Write code in Java: -Must be recursive import java.util.*; import java.lang.*; import java.io.*; //*Analysis goes here*   //*Design goes here* class AllPermutation { public static void displayPermutation(String s) { //*Code goes here* } public static void displayPermutation(String s1, String s2) { //*Code goes here* } } //*Driver class should not be changed* class DriverMain { public static void main(String args[]) { Scanner input = new Scanner(System.in); AllPermutation.displayPermutation(input.nextLine()); } }

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question

Write code in Java:

-Must be recursive

import java.util.*;

import java.lang.*;

import java.io.*;

//*Analysis goes here*

 

//*Design goes here*

class AllPermutation {

public static void displayPermutation(String s) {

//*Code goes here*

}

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

//*Code goes here*

}

}

//*Driver class should not be changed*

class DriverMain {

public static void main(String args[]) {

Scanner input = new Scanner(System.in);

AllPermutation.displayPermutation(input.nextLine());

}

}

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 two given methods:
void displayPermutations(str)
void displayPermutations (str1, str2) //helper
Note: Helper method, uses a loop to move a character from str2 to stri and recursively invokes it with a new stri and str2. The base case is that str2 is empty and
print stri to the console.
//Assume no duplicate characters or space in the input string
Transcribed Image Text: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 two given methods: void displayPermutations(str) void displayPermutations (str1, str2) //helper Note: Helper method, uses a loop to move a character from str2 to stri and recursively invokes it with a new stri and str2. The base case is that str2 is empty and print stri to the console. //Assume no duplicate characters or space in the input string
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning