Comparisons
Description
Use ==, !=, <, >, <=, and >=.
Explanation
The result is always true or false.
Example
boolean passed = score >= 40;← Chapter 2 — Core Syntax & Data
mixed
Comparison operators produce boolean answers. Programs use those answers to decide what should happen next.
Logical operators combine boolean conditions. They are useful when a rule needs more than one check, such as a score and attendance requirement.
Use ==, !=, <, >, <=, and >=.
The result is always true or false.
boolean passed = score >= 40;&& means and, || means or, and ! means not.
&& stops early when the first condition is false.
boolean eligible = score >= 40 && attendance >= 75;Use == for primitive equality. For object content, especially String text, use methods such as equals to express the comparison you mean.
public class LogicDemo {
public static void main(String[] args) {
int score = 72;
int attendance = 80;
boolean eligible = score >= 40 && attendance >= 75;
System.out.println(eligible);
}
}