Estoy bastante nuevo en estas cosas de codificación y tengo una tarea que se entregará en breve, en el que tenemos que codificar un juego de rol. Estoy trabajando en un trozo de mi juego basado Muerte-Note, donde Kira es elegir qué manera de matar usando Si los estados. Por alguna razón se dice "tipos incompatibles: char no pueden ser convertidos en booleano" y no tengo ni idea de por qué.
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!");
}
}
Esto sucede porque usted está utilizando un solo signo igual en su if
. Esto se utiliza para la asignación, que busca el operador igual doble ( ==
) que compara dos valores.
El compilador le está diciendo que la if
está esperando un boolean
(o una expresión que se resuelve a una boolean
) pero estás pasando en una misión en lugar de una comparación.
Tal vez puedas probar:
if (kill == 'a') {
// ...
}