A conditional statement is like a decision-maker in a program: it checks if something is true or false and then either runs certain code or skips it based on that result. Once you understand boolean expressions, you can use them in if statements—a type of conditional statement—to make decisions in your code. An if statement in Java begins with the keyword if, followed by a pair of parentheses ( ). Inside the parentheses is a boolean condition—something that can be either true or false. Then, you have a pair of curly brackets ({ }) containing the code you want to run only if the condition is true. If the condition is false, the code inside the braces is skipped.
int score = 85;
if (score >= 70) {
System.out.println("You passed the test!");
}
Output
You passed the test!