I have a method called displayWord that is supposed to compare each index of an array with another array and if the indexes match, it is supposed to execute this line displayedWord[i] = wordArray[i].
When I print the displayedWord, they are all question marks even thought the print statement executes so I know it is going into the if block.
Why is displayedWord always questions marks when I print it?
public static void displayWord(char[] correctGuesses, char[] wordArray) {
char[] displayedWord = new char[wordArray.length];
for(int i = 0; i < wordArray.length; i++) {
for(int j = 0; j < correctGuesses.length; j++) {
if(wordArray[i] == correctGuesses[j]) {
displayedWord[i] = wordArray[i];
System.out.println("they are the same");
} else displayedWord[i] = '?';
}
}
for(char c : displayedWord) {
System.out.print(c);
}
}
break;inside theifblock (afterSystem.out.println("they are the same");)correctGuessesandwordArrayhave the same length?wordArraywith every element ofcorrectGuesses, rather than just the element with the same index? Step through your program with the debugger.