Java: Comparing data types int and boolean

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>
<Look to the right of this box. That is how your post will look to everyone els
Here is the line to which i’m referring.
" Equality operators do not require that operands share the same ordering. For example, you can test equality across boolean, char, or int data types. "
Here is the link.
<Below this line, add a link to the EXACT exercise that you are stuck at.>

https://www.codecademy.com/en/courses/learn-java/lessons/introduction-to-java/exercises/equality-operators?action=lesson_resume
<In what way does your code behave incorrectly? Include ALL error messages.>

```

System.out.println(2==true)

<do not remove the three backticks above>**error:incomparable types:int and boolean**
1 Like

Hi boolean value are true or false

1 Like

Right you are, boolean is not a numeric type.

1 Like

thanks for the response,
but see when we use the code

char myChar = ‘A’;
int myInt = -2;
System.out.println(myChar == myInt);

the output is false

shouldn’t this also give error

char and int are both numeric, so that’s fine!

This explains what’s going on:
https://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.21
Reading just the bold paragraph probably says enough

1 Like

alphanumeric, aren’t they? Containing letters and/or numbers?

It’s an unsigned short (16 bits, 0 to 65535)

1 Like