if, else if and else
Branch on conditions. Braces are optional for one line, but recommended.
Example
public class Main {
public static void main(String[] args) {
int score = 72;
if (score >= 90) System.out.println("A");
else if (score >= 70) System.out.println("B");
else System.out.println("C");
}
}Result
B
Exercise
Else branch.
if (x) {} {}
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.