I am not sure why I am getting this problem. But basically I am shuffling a word and I am using an arrayList with loops.
This is my code and for debugging purposes I added a couple of lines.
//Declare and Initialize an arrayList for character checking
ArrayList<Boolean> jumbleVerfiy = new ArrayList<Boolean>();
for(int x = 0; x < chosenWord.length(); x++)
jumbleVerfiy.add(false);
while((chosenWord.length()) != (jumbledWord.length()))
{
//Generate random number for getting the random character
int verficationNumber = rnd.nextInt(chosenWord.length());
//Checks if the random number generated has been used before
if(jumbleVerfiy.get(verficationNumber) == false)
{
//Get the character from the randomly generated number and change the boolean array to keep track of
//letters used
jumbledWord += chosenWord.charAt(verficationNumber);
System.out.print(jumbleVerfiy.get(verficationNumber) + " " + verficationNumber);//debug
jumbleVerfiy.add(verficationNumber, true);
System.out.println(" " + jumbledWord + " " + jumbleVerfiy.get(verficationNumber));//debug
}
My output is as follows
false 3 r true
false 4 ry true
false 2 ryr true
false 1 ryra true
false 4 ryray true
tarry ryray
In this output 4 was changed to true on the second run but then when it loops it is set to false for some reason. So I keep getting a duplicate letter. I am not sure what the problem is. Would love some insight.
Thank you,