While trying to run a small program in java, I'm getting the following error:
HangmanSB.java:19: error: unexpected type
if (sentence.charAt(i) = " "){
^
required: variable
found: value
1 error
I tried reading the answers to a similar question posted on this website, yet I still can't seem to understand how to fix the error the program is giving me.
import java.util.Scanner;
class HangmanSB {
public static void main(String[] args){
Scanner keyboard = new Scanner(System.in);
String sentence = keyboard.nextLine();
int turns = keyboard.nextInt();
for (int turnsLeft = turns; turnsLeft > 0; turnsLeft--){
int length = sentence.length();
for (int i = 0; i < length; i++){
if (sentence.charAt(i) = " "){
System.out.println(" ");
}
else {
System.out.print("_");
}
}
}
}
}