if statements test a boolean expression and if it is true, go on to execute the following statement or block of statements surrounded by curly braces
if(x>10){
System.out.println("True!");
}
reminder: relational operators are used in boolean expressions to compare values and arithmetic expressions!
If statements can be followed by an associated else part to form a 2-way branch: one to be executed when the Boolean condition is true, and another set for when the Boolean condition is false
if(x>10){
System.out.println("True!");
}
else{
System.out.println("False");
}
A multi-way selection is written when there are a series of conditions with different statements for each condition.
Multi-way selection is performed using if-else-if statements such that exactly one section of code is executed based on the first condition that evaluates to true.
if(x>15){
System.out.println("X greater than 15");
}
else if(x>=10){
System.out.println("X greater than 10");
}
else{
System.out.println("X is less than 10");
}