Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Printing all possible combinations of a given word.

807603Nov 16 2007 — edited Dec 14 2007
Well I'm supposed to print all possible combinations of a given word(I'm writing this for the benefit of those who might not have guessed this from the subject). I've got some code but its horribly wrong. Could anyone point out any mistakes.
public class Try
{   
    public void display(String s)
    {   
        char ch[]=s.toCharArray();
        for(int i=0;i<ch.length;i++)
        {   
            String word="";
            word+=ch;
char c[]=new char[s.length()];
for(int j=0;j<ch.length;j++)
{
if(ch[j]!=ch[i])
c[j]=ch[j];
}
for(int j=0;j<ch.length;j++)
{
for(int k=0;k<ch.length;k++)
{
if(c[j]!=c[k])
word+=c[k];
}
word+=c[j];
System.out.println(word);
}
}
}
}
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 11 2008
Added on Nov 16 2007
14 comments
306 views