java - I am stumped by a seemingly simple syntax error -
java - I am stumped by a seemingly simple syntax error -
i creating hangman game in java, , running problem. in if statement on line 8, checking see if of characters in apple match char user inputs. error showing (unexpected type required: variable, found: value
scanner input = new scanner(system.in); string word1 = "apple"; system.out.print("guess letter: "); char guess = input.next().charat(0); for(int = 0; <= word1.length(); i++) { //check see if char @ position equals guess if(word1.charat(i) = guess) { //code logic inserted } }
if(word1.charat(i) == guess)// utilize "==" instead of "=" { //code logic inserted }
"=" means assigning value variable. "==" means comparing..
also, if you, utilize i < word1.length();
instead of i <= word1.length();
. potential arrayindexoutofboundsexception
screaming behind line...
java
Comments
Post a Comment