Logical Operators: && || !

Part of: Boolean Expressions & if Statements

Combining Conditions Logical operators combine or invert boolean expressions so a single if can test several conditions at once. Java has three: - && logical AND : true only when both operands are true - logical OR : true when at least one operand is true - ! logical NOT : flips true to false and false to true Truth Tables For AND and OR: - true && true is true; any other combination is false. - false false is false; any other combination is true. - !true is false; !false is true. Both age = 18 and hasLicense must be true for the message to print. Change either to false and the body is skipped. OR Example Only one side needs to be true. Day 7 makes the right operand true, so it prints Weekend. NOT Example The ! operator negates: Since raining is false, !raining is true. Precedence When mixing operators, Java applies precedence : ! binds tightest, then &&, then . So a b && c means a (b && c). Use parentheses to make intent explicit and avoid mistakes: Parentheses also improve readability. Combining relational and logical operators lets you express rich real-world rules in one clear condition.

Challenge: Eligible to Vote and Drive