I am working on a "guess the secret word" game in Java. I have a char array containing _'s relative to the amount of letters in the secret word. I am writing a method that will replace the _'s with the guessed letter. My problem is when I have multiple of the same letters; only the first occurrence is replaced. This is my code:
public void replaceBlank(char letter){
if(guessLetter(letter)==true){
int x=getSecretWord().indexOf(letter);
charArray[x]=letter;
}
}
The code inside the if is the piece that deals directly with replacing the _'s. I'm thinking that I need a for loop, but I'm not sure how to implement it.
if(guessLetter(letter))is enough