Biểu thứcBoolean compound
Đã giới thiệu| English | Ý nghĩa |
|---|---|
| AND/ænd/ | và logic |
| OR/ɔː/ | hoặc logic |
| NOT/nɒt/ | không logic |
| short-circuit evaluation/ʃɔːt ˈsɜːkɪt ɪˌvæljuːˈeɪʃn/ | đánh giá ngắn mạch |
AND and OR
- Combine conditions with
&&(logical AND 逻辑与) and||(logical OR 逻辑或). a && bistrueonly when both aretrue.a || bistruewhen at least one istrue.- "Is the number between 1 and 10?" →
x >= 1 && x <= 10.
NOT reverses
!(logical NOT 逻辑非) flips a Boolean:!trueisfalse,!falseistrue.!(x > 5)istrueexactly whenxis not greater than5.- NOT applies to the expression right after it — use parentheses for clarity.
- Double negation cancels:
!!aequalsa.

Truth table for &&, || and !, with short-circuit evaluation 短路求值
Short-circuit evaluation
&&and||stop as soon as the answer is known — this is short-circuit evaluation.- For
a && b: ifaisfalse, the result isfalseandbis never evaluated. - For
a || b: ifaistrue, the result istrueandbis skipped. - This lets you guard:
x != 0 && 10 / x > 2avoids dividing by zero.
Truth tables and parentheses
- A truth table lists every combination of inputs and the expression's result.
- With two variables there are $4$ rows; build one to check tricky logic.
- Use parentheses to make precedence explicit:
(a && b) || c. - Without them,
&&binds tighter than||— a common source of confusion.
Short-circuiting isn't just an optimization — it can prevent errors. In x != 0 && 10 / x > 2, if x is 0 the left side is false, so Java never evaluates 10 / x and avoids a divide-by-zero. Swap the order and it crashes. Also, && binds tighter than ||, so parenthesize mixed expressions to say exactly what you mean.
Is x outside 1–10?
x < 1 || x > 10→truewhenxis too small or too big.x = 15→false || true→true(outside).x = 5→false || false→false(inside).
Combine conditions with && (both true), || (at least one true), and ! (reverse). Java uses short-circuit evaluation: &&/|| stop once the result is known (handy for guards like x != 0 && 10/x > 2). Build a truth table for tricky logic and use parentheses — && binds tighter than ||.
AND của hai điều kiện
&& chỉ true khi cả hai đầu vào đều true.
a && b là true khi...
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
&& (AND) cần cả hai toán tử đều true.
Trong a && b, nếu a là false, thì b là...
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
&& short-circuit: một vế trái false khiến kết quả là false ngay lập tức.
!(true) đánh giá ra false.
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
! đảo ngược giá trị Boolean.
Với x = 5, x < 1 || x > 10 đánh giá ra gì?
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
false || false → false (5 nằm trong khoảng 1..10).
Hành vi mà && và || dừng ngay khi kết quả đã rõ ràng được gọi là ___-circuit evaluation (một từ).
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
Short-circuit evaluation dừng sớm.