DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2005

    Question Word sorting / permutation w/ array?

    Hello everyone, I have a quick question regarding a (most likely) simple problem I am having with a Java program.

    I am trying to find out how to display possible instances (permutations) of four words. I am putting these four words in an array that stores a max of 4.

    I know the final code has to use an array, and I am guessing a couple of for loops as well. Am I even right on this assumption?

    How I have it is getting four input boxes as strings and then have it display the possibilities. So, for example, the words one, two, three, and four would display the 24 possible combinations on one line per combination:
    1) one two three four
    2) two one three four
    3) two one four three
    4) etc...

    The only code I have that is at all remotely similar is permutations that actually scramble the acutal words (example: OK sorted to KO). Does anyone know a simple way to do this, which involves an array and not several pages of code? My problem is that I am unfamiliar with how Java does / can do permutations of words.

    Thanks in advance!
    Last edited by boomchip; 11-14-2005 at 08:01 AM.

  2. #2
    Join Date
    Dec 2004
    San Bernardino County, California
    In your array of words you are storing strings at each of four positions. Your permutation is just a permutation of indexes 0 to 3 - then plug in the values from the original array ...

    It should be easy to adapt the code you have to your problem since a word can be thought of and addressed as an array of characters ... and this is what your code is probably doing.

Similar Threads

  1. Replies: 5
    Last Post: 11-12-2005, 01:38 PM
  2. Dynamically allocating a 2d array
    By nnp in forum C++
    Replies: 6
    Last Post: 11-01-2005, 09:05 AM
  3. Replies: 2
    Last Post: 04-15-2005, 09:06 PM
  4. Accessing jagged array values
    By Jason Salas in forum ASP.NET
    Replies: 2
    Last Post: 04-20-2003, 11:39 PM
  5. Sorting an array of hashtables
    By Jim Drohan in forum Java
    Replies: 2
    Last Post: 11-22-2000, 11:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

By using this site, you agree to the Privacy Policy