Equality
Any two ints can be inspected to see if their value is equal by using the == operator.
Unlike the previous operators, which all take ints and produce ints as their result, == takes two ints
and produces a boolean as its result.
void main() {
// 1 is never equal to 2
// this will be false
boolean universeBroken = 1 == 2;
IO.println(universeBroken);
int loneliestNumber = 1;
int canBeAsBadAsOne = 2;
// this will be true
boolean bothLonely = loneliestNumber == (canBeAsBadAsOne - 1);
IO.println(bothLonely);
}
It is very important to remember that a single = does an assignment. Two equals signs == checks for equality.
The opposite check, whether things are not equal, can be done with !=.
void main() {
// 1 is never equal to 2
// this will be true
boolean universeOkay = 1 != 2;
IO.println(universeOkay);
}