Hi! I'm having trouble solving this problem. Since it's finals week here at my school the Computer science tutors left early and I need just this simple problem finished by tomorrow @ noon.
I'm working on the hangman game as my final project. I've got everything done, except for this silly thing. I'm trying to detect if a user entered a letter already, and if they did, loop the input until they enter a letter that's not in this string array. Everything is working except that I can't exit this loop! Here's my code:
while (contains == true) {
if (contains = true) {
userInput = JOptionPane.showInputDialog(null,"This letter has already been entered! Please enter a letter");
c = userInput.charAt(0);
b++;
for (int u=0;u<lettersEntered.length;u++) {
if (lettersEntered[u] == c) {
contains = true;
}
}
}
else {
lettersEntered[g]=c;
System.out.println(lettersEntered[g]);
contains = false;
}
}
Could someone please help my find my problem?! I don't know why it's not exiting the while loop. Whenever the boolean contains is false, it's supposed to exit the loop, but it's not. Someone please help! Thanks!