I'm coding part of an RPG game and there's an error saying "incompatible types: char cannot be converted into boolean" (java, bluej)

mak :

I'm pretty new to this coding stuff and I have an assignment due soon, where we have to code an RPG game. I'm working on a chunk of my Death-Note based game where Kira is choosing what way to kill using If statements. For some reason it says "incompatible types: char cannot be converted into boolean" and I have no clue why.

public class test
{
    public static void main (String args[])
    {
        new test();
    }
    
    public test ()
    {
    System.out.println ("You take the notebook with you and walk to the nearest");
    System.out.print (" comic book store where you see a young girl being robbed by a"); 
    System.out.print (" group of men. The man who appears to be the leader of the gang speaks."); 
    System.out.print (" \"My name is Takuo, Shibui-Maru, that’s Shibutaku for short. Heh heh.\"");
    System.out.print ("You decide to write his name and see what happens.");
    System.out.print ("Do you choose to kill him by:");
    
    int points = 50;
    System.out.println (" ");
    char kill = IBIO.inputChar ("a)heart attack or b)fire: ");
    if (kill = 'a') //heres the error
    {
    points = +10;
    System.out.println (" Within minutes, the man falls to the ground and the girl runs away. The death note works! +points+ ");
}
    else
    {
    points = -20;
    System.out.println (" All of a sudden, flames engulf the comic book store."); 
    System.out.println (" You attempt to leave the store as quickly as possible but have trouble seeing.");
    System.out.println (" You return safely with the notebook in your hands, but an innocent old man fails to come outside in time. +points");
}
    System.out.println ("So it wasen't a myth!");
}
}

Yanick Bélanger :

This happens because you're using a single equal sign in your if. This is used for assignment, you're looking for the double equal operator (==) which compares two values.

The compiler is telling you that the if is expecting a boolean (or an expression which resolves to a boolean) but you're passing in an assignment instead of a comparison.

Try this instead:

if (kill == 'a') {
    // ...
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=277598&siteId=1