Let i1=10, i2=-20, i3=30.
i1 < 12 true
Booleans can be stored as variables.
An expression like a < b < c is illegal. Again let i1=10, i2=-20, i3=30.
(i1>10) || (i1==10) false || true true
The && and || have lower precedence than the relational operators, but
parentheses are still useful because they enhance readability.
The && and || are lazy operators that evaluate only the left operand only when that suffices.
Consider:
Don't forget to try the problems in the book as well and see how well you know how to do these (Chapter 6 (4 in new edition)) has solutions at the bottom of the page. Also truth tables are good to remember.
i1 < 10 true
i3 == i1 false
i1 != 2 true
i1 < 10 false
i2 > 0 false
2*i1 == i2+40 true
i2*(-1) != i1+i1 false
private boolean tooBig;
tooBig = true;
tooBig = i1 > 10;
(i1>10) || (i1<0) false || false false
(i1>0) && (i1<5) true && false false
(i1>0) && (i1<20) true && true true
(5 == 4) && ????
Does it matter what the second operands are?
(5 != 4) || ????Harder
Now you write them.
Consider