← Back to Week 1 Hub

if / else if / else Flowchart

Workbook 1c, p.97-100 — See how Java decides which branch to run

Variable: int age =
18

📝 Java Code

int age = 18; // ← slider controls this
if (age >= 21) {
System.out.println("You can drink alcohol");
} else if (age >= 18) {
System.out.println("You can vote");
} else if (age >= 16) {
System.out.println("You can drive");
} else {
System.out.println("You are too young");
}
Output: You can vote

📊 Flowchart

Start age >= 21? Yes "drink alcohol" No age >= 18? Yes "can vote" No age >= 16? Yes "can drive" No "too young" End
Variable: int temp =
72
°F

📝 Java Code

int temp = 72; // ← slider controls this
if (temp >= 90) {
System.out.println("It's hot outside!");
} else if (temp >= 70) {
System.out.println("It's warm and nice");
} else if (temp >= 50) {
System.out.println("It's cool, grab a jacket");
} else {
System.out.println("It's cold, stay inside!");
}
Output: It's warm and nice

📊 Flowchart

Start temp >= 90? Yes "hot outside!" No temp >= 70? Yes "warm and nice" No temp >= 50? Yes "grab a jacket" No "cold, stay inside!" End

💡 Key Concepts

← Scanner Buffer Logical Operators →