我对这些编码东西还很陌生,很快就要完成一项作业,我们必须在该处编写一个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
发生这种情况是因为您在中使用了一个等号if。这用于赋值,您正在寻找==比较两个值的double等于运算符()。
编译器告诉您,if期望boolean(或解析为的表达式boolean),但是您传递的是分配而不是比较。
尝试以下方法:
f (kill == 'a') {
// ...
}
回答来源:Stack Overflow
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。