7
- Whate
selection statement in Java ? Geplein write the
syntax of bi-directional and multi directional selection
statements
Answers
Answer:
ggh
Explanation:
xghccuufcugufology jliyrdf
Answer:
Explanation:
Java has three types of selection statements. The if statement either performs (selects) an action, if a condition is true, or skips it, if the condition is false. ... The switch statement performs one of many different actions, depending on the value of an expression.
1. Bi-directional flow of control:
if...else statement:
if (condition)
{
// code will be executed if the 'if condition' becomes true.
}
else
{
// code will be executed if the 'if condition' becomes false.
}
Example (Rough Skeleton of if...else statement in java)
int age=12;
if (age>=18) //12>=18 -> Condition becomes false. diverts to else block
{
System.out.println("Major");
}
else
{
System.out.println("Minor");
//if condition fails, the code in else block executes.
}
//Results 'Minor' as output.
2. Multiple branching of control:
else if statement:
if (condition1)
{
// condition1==True -> executes if block
}
else if (condition2)
{
// condition1=False and condition2=True -> executes else if block
}
else
{
// condition1=False and condition2=False -> executes else block
}
Example (Rough Skeleton of else if statement in java)
int marks=62;
if (marks<=50) //62<=50 -> false -> goes to else if
{
System.out.println("Better luck next time!");
}
else if (marks>=51 && marks<=80) //62>=51 && 62<=80 -> true
{ //executes this block.
System.out.println("Good!");
}
else
{
System.out.println("Excellent!");
}
//Prints 'Good!' is output.