Language syntax

Conditional AND and OR

Boolean AND evaluates the right expression only when the left is true; OR evaluates it only when the left is false. Use a guard before a risky dereference or division. Both expressions yield boolean.

Formal Syntax & Structure

java syntaxjava
left && right; left || right

Working Example

Example Snippetjava
public class Main {    public static void main(String[] args) {        int count = 0;        System.out.println(count > 0 && 50 / count > 2);        System.out.println(count == 0 || 50 / count > 2);    }}
Java Reference