Boolean Operators
Purpose:
- To make comparisons between expressions that yield
trueorfalse.
Mechanics:
<expression1> <operator> <expression2>
Example:
boolean temp = (num1 == num2);
Usage:
- <expression1> and <expression2> are represented by constants, variables, or any combination of parenthesized subexpressions.
- <operator> is any Java boolean or comparison
operator:
!= not equal to > greater than < less than >= greater than or equal to <= less than or equal to == equal to
Restrictions:
- The expressions can be integers, reals, or any other data type, but the expressions on either side of the operator must be of the same type.
- Comparisons are expressions, not complete Java statements. A
comparison yields
trueorfalse, which must be used in the context of a complete Java statement. - Note the difference between the = assignment operator (used for assigning values to variables) and the == equals operator (used in logical comparisons).
email suggestions to: cs015tas@cs.brown.edu
