Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 260
  • Last Modified:

java programming



This assignment will be creating all the permutations of a word using upper and lower case letters.  For a word that is n letters long the number of permutations is 2n.  For instance; given the word "are" the possible permutations include:

are
Are
ARe
ARE
ArE
aRe
aRE
arE

Please help me to write a java progarm?
0
sraveend
Asked:
sraveend
  • 5
  • 4
1 Solution
 
sciuriwareCommented:
No, homework is forbidden.

The only thing I will say is that every character has 2 states,
you might couple these to an array of booleans and
that to a split binary number of which the bits indicate the state (0 == lowercase).
By incrementing the binary number you can decode all possible strings.

Just try.

;JOOP!
0
 
sraveendAuthor Commented:
Could u please give me an example !!!
0
 
sciuriwareCommented:
You must change characters, so you must choose between a char[] (very fast) and a StringBuffer (flexible).

For 3 characters you need:                       char[] array = new char[3];
You can count from 0 to 7 to address them:
       for(int i = 0;  i < 8;  ++i)
You can address those 3 characters by an integer:
              for(j = 0;  j < 3;  ++j)
To address 'array' from 'i' :
       if((i & (1<<j)) == 0)
       {
             array[j] = Character.toLowerCase(array[j]);
       }
       else
       {
             array[j] = Character.toUpperCase(array[j]);
       }


It's your turn now.....
;JOOP!
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
sraveendAuthor Commented:
Thanks a lot,it helped me to write the program correctly!
0
 
sciuriwareCommented:
Ok, you may click [Accept] now.

Feel free to learn here, not just to copy from here (that's the rules).

;JOOP!
0
 
sraveendAuthor Commented:
Am sorry i searched & i coudn't get the link Accept........
0
 
sciuriwareCommented:
After every comment ....
0
 
sraveendAuthor Commented:
I could view accept when u gave me the first solution ,but now i could see only a word comment ,after every comment
0
 
sciuriwareCommented:
Are you logged in as yourself?

;JOOP!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now