In the for loop, the posted code will always set hanged to false. There is no need to set hanged to false if that was its initial value because its value won't change unless the code sets it to true...
Type: Posts; User: Norm
In the for loop, the posted code will always set hanged to false. There is no need to set hanged to false if that was its initial value because its value won't change unless the code sets it to true...
Look at and think about how you are using the hanged variable.
The new variable will be used to detect when: "the user guesses the wrong character"
or a better way to look at it: when the user...
What are you trying to count?
The loop compares a single user input against all the letters in word.
Do you want to count all the letters in the word that don't match the user's input?
Should...
What do these two lines of code do? Why are they both there?
dash[b] = guess.charAt(0);
dash[word.indexOf(guess.charAt(0))] = check;
Why does the code set...
When should the hanged variable be set to true?
The code looks like it sets hanged true when ONE character matches.
Shouldn't all the characters have been matched before hanged is set true?
...
Post the code on line 64.
Try debugging the code on line 64 by adding a println just before it that prints out the length of the String, the value of the String and the value of the index. The...
Did you look at line 64 to see why the code is using an index value that is past the end of the String?
Does that mean you have solved your problem?
That is NOT a compiler error. That error is when the code is executed.
The code at line 64 uses an index value that is past the end of the String. A String of length 2 does not have a char at index...
if dashArray is a char array, then you can use the == operator to compare an element to a char:
if(dashArray[ix] == someChar) { ...
When you get compiler errors, copy the full text of the error...
A String and a char should never return true with the equals() method.
Can you make dashArray a char array
or use charAt(0) with the String in dashArray to get a char value to compare with ==?
What are the values of dashArray[b] and word.charAt(b) when it doesn't work?
One possible problem is that dishArray holds String values and charAt() returns a char.
Also posted at: Hangman game...