Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Java program using recursion that will display, one per line, all possib

ID: 3641052 • Letter: W

Question

Write a Java program using recursion that will display, one per line, all possible scramblings of a word that is given on the command line. If there is no word or more than one word on the command line then the program should produce no output.

Running the program as:

> java Scramble abc

should generate this output:

abc
acb
bac
bca
cab
cba

Running as:

> java Scramble abcd

should generate this output:

abcd
abdc
acbd
acdb
adbc
adcb
bacd
badc
bcad
bcda
bdac
bdca
cabd
cadb
cbad
cbda
cdab
cdba
dabc
dacb
dbac
dbca
dcab
dcba

And so on.

Explanation / Answer

import java.io.*; public class permutation { public static void main(String args[]) throws IOException{ String str; System.out.println("Enter the initial string"); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); str=br.readLine(); System.out.println("Permutations are :"); permute("", str); } public static void permute(String beginningString, String endingString) { if (endingString.length()
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote