If ... Else
if runs code when a condition is true. Add else if for more cases and else for the rest. Always use braces, even for one line.
Example
int score = 72;
if (score >= 85) {
System.out.println("Distinction");
} else if (score >= 70) {
System.out.println("Pass");
} else {
System.out.println("Retake");
}Result
Pass
Exercise
Run when the condition is false.
if (ok) {} {}
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.