Conditional statements allow you to make decisions based on certain conditions. Conditions specify a set of decision-making statements with Boolean expressions. Boolean expressions are evaluated as true or false.
There are 4 types of conditional statements in Java:
The If statement consists of a Boolean expression that is evaluated to a Boolean value. If the value is True, the block is run; otherwise, the next statement is executed.
If-else statements consist of two statements: if and else. When the expression in the if-statement is true, the if block is run; otherwise, the else block is executed.
The If-Else-If statement, sometimes known as a ladder, tests a set of conditions using successive if-else if-else statements. The statement that meets the outcome will be performed. When no condition meets the desired result, the default else statement is executed.
Switch statements evaluate a set of conditions using one or more cases that are compared to the switch expression. The case that meets the result will be performed. When no cases match the result, the default case is executed.