if, else, and Boolean ExpressionsUnit 3 · Decisions and Boolean logic
A condition evaluates to true or false. Use == to compare primitive values, && for “and,” || for “or,” and ! for “not.” Use .equals for String content.
if (mark < 0 || mark > 100) {
System.out.println("Invalid mark");
} else if (mark >= 50) {
System.out.println("Pass");
} else {
System.out.println("Try again");
}Put the most specific invalid cases first. Braces make the controlled block explicit and prevent accidental bugs when code changes.
username.equals(...), not username == ....1 < mark < 10 not work in Java?if (ready == true)?Mastery task: Write a fare calculator with validated age and distance inputs, documenting each boundary decision.