Java
Making decisions
A practical reference with examples you can run.
Introduction
A conditional chooses an action based on a true-or-false expression. Think about the boundary: does a score of exactly 10 belong in the first branch? Test values below, at, and above that boundary.
Syntax & example
public class Main {
public static void main(String[] args) {
int score = 12;
if (score >= 10) {
System.out.println("Ready for the next step!");
} else {
System.out.println("Keep practicing!");
}
}
}Expected output
Ready for the next step!
Common mistakes
- Using a variable before assigning a value to it.
- Mixing text and numbers without converting deliberately.
- Skipping an empty input or a boundary value when testing.
Practice
Change the score and test both branches.
Main.javaYour ideas, in code.
Loading your editor…
Run your code to see the output here.
Ready to buildUTF-810 lines