开发者社区> 问答> 正文

我正在编码RPG游戏的一部分,并且出现一个错误,提示“不兼容的类型:char无法转换为布尔值”

我对这些编码东西还很陌生,很快就要完成一项作业,我们必须在该处编写一个RPG游戏。我正在开发一款基于Death-Note的游戏,其中Kira正在选择使用If语句杀死的方式。由于某种原因,它说“不兼容的类型:char不能转换为boolean”,我也不知道为什么。

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!");
}
}

问题来源:Stack Overflow

展开
收起
montos 2020-03-25 18:39:24 773 0
1 条回答
写回答
取消 提交回答
  • 发生这种情况是因为您在中使用了一个等号if。这用于赋值,您正在寻找==比较两个值的double等于运算符()。

    编译器告诉您,if期望boolean(或解析为的表达式boolean),但是您传递的是分配而不是比较。

    尝试以下方法:

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

    回答来源:Stack Overflow

    2020-03-25 18:39:46
    赞同 展开评论 打赏
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Flash Player最新安全特性分析 及绕过思路 立即下载
Flash Player最新安全特性分析及绕过思路 立即下载
软件定义的数据智能 立即下载