I am currently writing a program in which you input a word and the program then outputs all of the different ways the characters can be moved round into anagrams. I have wrote a way of turning the command line argument into a char array using the toCharArray() now I need to write a boolean array to see if the character has been used before. Any help?

If you know how to work with a char array then a boolean array is just the same except that all the values are true or false. Where exactly are you stuck?

I have declared the boolean array but I don't know exactly how to use it to declare if a character has been used before, true if it has false if it hasn't

What are you using as the index of the array? I'd use the character's integer value - but what do you do if you have a repeated character?

public class Anagrams

  private static char[] currentIndex;  

  public static void main(String[] args)
    currentIndex = args[0].toCharArray;
    charValues = new String[currentIndex];
    char[] currentPermutation = new char;
    boolean[] wordInUse = new boolean[];   

    private static int[] charValues;

  private static void printPermutations(String currentIndex)
    if(currentIndex == charValues.length)

here is what I have so far, am I kind of on the right lines here or am I way off (first time using boolean arrays)

I'm afraid I don't understand your logic here. Maybe you could explain in English what you're trying to do with this, and what you want to do next.

Whether the use of the boolean array is right depends on what is the algorithm you are implementing. There's no clue as to your intended algorithm, so no way for anyone to comment.
Do you have a written description of the algorithm? Do you have it in your head? Could you use it with pencil & paper if someone gave you an arbitrary word?
If you can't answer "yes" to at least one of those questions then it's too soon to be coding anything.
ps: The obvious way to do this involves recursion, but there are bound to be other ways as well.

Again! Hi Jon.

Edited 5 Years Ago by JamesCherrill: n/a

This question has already been answered. Start a new discussion instead.