Java - Decision Making statements
Java - Decision Making Statements
- Conditional operations are enabled in java programs through its relational and logical operators.
- Thus a conditional expression is evaluated and a Boolean literal value, true or false is returned.
- Code execution flow is based on this value and hence such conditional expressions are termed as Decision Making Statements.
- Two types of decision making statements are available in Java:
- If Statement
- Switch case Statement
If Statements :
- Executes a single or a block of statements based on the Boolean condition present near the keyword “if”.
Switch Case Statement :
- Tests an expression of type char, byte, short, or int against a set of values.
- Based on the matching value, a case branch is selected and executed.
- If none of the value matches, then the default case statements are executed as shown below:
Switch case statement