System.out.println("ready: " + ready); System.out.println("willing: " + willing); System.out.println("able: " + able); Output ready: true willing: true able: true Self-Check 2-9 Evaluate the following expressions to their correct value. int j = 4; int k = 7; a. e. (j + 4) == k j < k b. f. j == j == 0 4 c. g. j >= k j == (j + k - j) d. h. j != k (k - 5) <= (j + 2) Boolean Operators Java has three Boolean operators! to represent logical not, to represent logical or, and to ¦¦ && represent logical and. These three Boolean operators allow us to write more complex boolean expressions to express our intentions. For example, this boolean expression shows the boolean operator (&&) applied to two boolean operands to determine if test is in the range of 0 “and” through 100 inclusive. (test >= 0) && (test <= 100) Used in assertions, this expression evaluates to true when test is 97 and false when test Boolean is 977: When is When is test 97 test 977 (test >= 0) && (test <= 100) (test >= 0) && (test <= 100) ( 97 >= 0) && ( 97 <= 100) (977 >= 0) && (977 <= 100) true && true true && false true false Since there are only two Boolean values, true and false, the following table shows every possible combination of Boolean values and operators and !, ¦¦, &&: boolean operator “not” ! Expression Result ! false true ! true false boolean operator “or” ¦¦ Expression Result true ¦¦ true true true ¦¦ false true false ¦¦ true true false ¦¦ false false boolean operator “and” &&
System.out.println("ready: " + ready); System.out.println("willing: " + willing); System.out.println("able: " + able); Output ready: true willing: true able: true Self-Check 2-9 Evaluate the following expressions to their correct value. int j = 4; int k = 7; a. (j + 4) == k e. j < k b. j == 0 f. j == 4 c. j >= k g. j == (j + k - j) d. j != k h. (k - 5) <= (j + 2) Boolean Operators Java has three Boolean operators! to represent logical not, ¦¦ to represent logical or, and && to represent logical and. These three Boolean operators allow us to write more complex boolean expressions to express our intentions. For example, this boolean expression shows the boolean “and” operator (&&) applied to two boolean operands to determine if test is in the range of 0 through 100 inclusive. (test >= 0) && (test <= 100) Used in assertions, this Boolean expression evaluates to true when test is 97 and false when test is 977: When test is 97 When test is 977 (test >= 0) && (test <= 100) (test >= 0) && (test <= 100) ( 97 >= 0) && ( 97 <= 100) (977 >= 0) && (977 <= 100) true && true true && false true false Since there are only two Boolean values, true and false, the following table shows every possible combination of Boolean values and operators !, ¦¦, and &&: ! boolean “not” operator Expression Result ! false true ! true false ¦¦ boolean “or” operator Expression Result true ¦¦ true true true ¦¦ false true false ¦¦ true true false ¦¦ false false && boolean “and” operator