File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes permutation & combination Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "permutation & combination" Watch "permutation & combination" New topic

permutation & combination

vijay Krishnan

Joined: Jul 27, 2006
Posts: 14
hello all,

i need one program that will give the output , if the input is like this,

input keyword = "dell desktop computers"
output =

"Dell Desktop"
"Dell Computers"
"Desktop Dell"
"Desktop Computers"
"Computers Dell"
"Computers Desktop"
"Dell Desktop Computers"
"Dell Computers Desktop"
"Desktop Dell Computers"
"Desktop Computers Dell"
"Computers Dell Desktop"
"Computers Desktop Dell"

thanks in Advance.
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Hopefully, no-one will just give you a solution. If you have had a go and are having trouble, show what you've done and explain the problems. Then I'm sure people will help.

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Sidd Kulk
Ranch Hand

Joined: Feb 20, 2007
Posts: 152
One thing is sure, you need to use recursion. Design an algorithm something like this:

You send the last two words of the statement to a method, which alters the sequence and returns the new sequence, which can be appended to the current string. This can be recursively called.

Hope you get some hint from this.

[ April 13, 2007: Message edited by: Sidd Cool ]
marc weber

Joined: Aug 31, 2004
Posts: 11343

Try describing the process (algorithm) you used to get the output example above. Once you have these steps described in English, then you can start writing Java code to perform these steps.

For example: I started with 3 words. First, I listed the possibilities using a single word. (- insert how you did this -) Next, I listed the possibilities using 2 of the 3 words...

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
pete stein

Joined: Feb 23, 2007
Posts: 1561
Also have a look here and here.

Good luck with your project!
I agree. Here's the link:
subject: permutation & combination
It's not a secret anymore!