In this section, we will discuss about Decision-making Statements in java 7. This is one type of control flow statement.
Decision-making Statements :
This kind of control statements is used where you need to take any decision under certain conditions. We write some statements under that condition. Following are the statements which comes under Decision making-
If Statement :
If statement is one of the basic control flow statements. It checks the condition written in if and if condition is satisfied then it executes the block of statements. Otherwise it jumps out of the block. You can also write else part of if by using keyword else.
You can also use multiple if Statement that means you can use nested if-else statements.
Switch Statement :
Switch statement is another decision-making statement used to control the flow of program. Like if-else statements, switch statement holds many conditions to execute. It contains many cases and execute one of them according to the tested variable.
case value1 : statements.....
case value2 : statements.....
case value n : statements.....
default : statements....
Conditional Operator Statement :
Conditional operator is also known as ternary operator. It checks the
condition if true then expression first executes otherwise the second expression
It uses 2 operators (? and :) and 3 operands.
condition ? expression1 : expression2
Liked it! Share this Tutorial