Not
Booleans can also be "negated" using the "not" operator - !
.
boolean haveOreosInHouse = true;
boolean stuckToCalorieLimit = !haveOreos;
So in this case, I have stuck to my calorie limit if there are not Oreos in the house.
haveOreosInHouse | stuckToCalorieLimit |
---|---|
false | true |
true | false |