Recursive method to print all permutations of a string, JAVA Programming

Assignment Help:

Objectives

_ Creating and compiling a simple program

_ Designing classes

_ Use of recursive algorithms

_ Learn basic combinatorics  

Task: string permutation

Write a recursive method to print all permutations of a string. For example, for a string "abc", the output would be:

abc

acb

bac

bca

cab

cba

Write a program to test your method.

The program should prompt the user to enter a string. Then the program should display all the possible permutations. You can assume that all characters in the input string are different.

Hint:

Declare the following two helping methods:

void displayPermutations(String text)

and

void displayPermutations(String done, String todo)

The first method invokes displayPermutations( "", text ). The second method uses a loop to move a character from todo to done and recursively invokes it with a new todo and done. The base case is when todo string is empty. In this case the method prints done

Example

Note:

user entered values are shown in bold.  

Example 1

This program prints out all permutations of a string.

Enter a string? dome

There are the following permutations:

dome

doem

dmoe

dmeo

deom

demo

odme

odem

omde

omed

oedm

oemd

mdoe

mdeo

mode

moed

medo

meod

edom

edmo

eodm

eomd

emdo

emod

Example 2

This program prints out all permutations of a string.

Enter a string? one

There are the following permutations:

one

oen

noe

neo

eon

eno  

Important Notes

1. For the purposes of this assignment, you can assume that the user will only enter  valid values.

2. In your program you must define and make use of at least the two methods:

a. displayPermutations(String text) and

b. displayPermutations(String done, String todo) as described above.

3. Test your program. In particular, be sure to test it on turing before you submit it.


Related Discussions:- Recursive method to print all permutations of a string

Lookupdispatchaction and dispatchaction, What is difference among LookupDis...

What is difference among LookupDispatchAction and DispatchAction? Ans) The difference among LookupDispatchAction and DispatchAction is that the actual method that gets known in

I want hall rental website, I want Hall Rental Website Project Descripti...

I want Hall Rental Website Project Description: I want to prepare website for my party venue where i will post the photos and detail of place along with availability calendar

Help, I can''t figure out how to do this question: "Given two linear equati...

I can''t figure out how to do this question: "Given two linear equations: ax + by + c = 0 and dx + ey + f = 0" solve for x and y. A, b, c, d, e, and f being inputted from the user.

Explain the different kinds of exceptions, Explain The different kinds of e...

Explain The different kinds of exceptions ? Checked Exceptions  : Environmental error in which cannot necessarily be detected through testing; e.g. broken socket, disk full,

Stream as an object, What interface must an object implement before it can ...

What interface must an object implement before it can be written to a stream as an object?      Ans) An object must execute the Serializable or Externalizable interface before i

Java Login/Register Web CMS, I need help setting up and fleshing out a basi...

I need help setting up and fleshing out a basic outline/structure for a basic Java web app using an MVC pattern

What is setter methods explain with an example, What is Setter Methods expl...

What is Setter Methods explain with an example? Setter methods, also called as mutator methods, merely set the value of a field to a value specified through the argument to the

Padovan series, write a program in java using array and scanner class to ge...

write a program in java using array and scanner class to generate padovan series

What is the use of mapmessage, A MapMessage carries name-value pair as its ...

A MapMessage carries name-value pair as its payload. Therefore its payload is same to the java.util.Properties object of Java. The values can be Java primitives or their wrappers

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd