Java.Core.What logical operations and operators do you know?

1. Logical AND (&&)

The AND (&&) operator returns true only if both operands are true. Otherwise, it returns false.

ExpressionResult
true && truetrue
true && falsefalse
false && truefalse
false && falsefalse

Example

2. Logical OR (||)

The OR (||) operator returns true if at least one operand is true. It returns false only if both are false.

ExpressionResult
true || truetrue
true || falsetrue
false || truetrue
false || falsefalse

3. Logical NOT (!)

The NOT (!) operator reverses a Boolean value:

  • !truefalse
  • !falsetrue

4. Logical XOR (^) (Exclusive OR)

The XOR (^) operator returns true only if the operands are different.
It returns false if both are the same.

ExpressionResult
true ^ truefalse
true ^ falsetrue
false ^ truetrue
false ^ falsefalse
This entry was posted in Без рубрики. Bookmark the permalink.

Leave a Reply

Your email address will not be published.