I'm making a simple hangman game. The code below updates the letters so it's checking if the guessed letter is in the word properly. However, it won't store the letter if a second correct letter is guessed. For example, for "moose", if I guess 'o' then it will print out (#oo##), then if I guess 'e', it will print out ####e. Maybe it has something to do with the else statement? I'm fairly new to this so any tips or just documentation would help. Thanks!
public static boolean updateWithGuess(char[] knownLetters,
char guessedLetter,
String word) {
boolean found = false;
for(int i = 0; i < word.length(); i++) {
if(word.charAt(i) == guessedLetter) {
knownLetters[i] = guessedLetter;
found = true;
}
else {
knownLetters[i] = BLANK;
found = false;
}
}
return found;
}
knownLetters[i] = BLANK;? if all positions are initially blank, there is no need to assign them to blank again