Page 123 - CA_Blue( J )_Class10
P. 123
19 if(phy_marks>90)
20 System.out.println("Got more than 90% in Physics.");
21 if(chem_marks>90)
22 System.out.println("Got more than 90% in Chemistry.");
23 if(comp_marks>90)
24 System.out.println("Got more than 90% in Computer.");
25 System.out.println("----------------------------");
26 }
27 }
You will get the following output:
7.2.4 The if…else…if Statement
Sometimes, we may face a situation in which Start
we need to check multiple conditions and
only any one of them will evaluate to true.
For example, if condition1 satisfies, then after
executing statement 1, the control goes to the Input a, b, c
statement after the else statement (which is
supposed to be the last statement of the if…else true
ladder). If condition 1 does not satisfy, then it if(a>0) a is more than 0
checks condition 2 and depending on the result
executes statement 2 and exits from the if…else false
ladder. Following is the syntax of the if…else…if
statement: else true
if(b>0) b is more than 0
if (Condition1)
Statement1;
false
else if (Condition 2)
Statement 2; true
else
else if (Condition 3) c is more than 0
if(c>0)
Statement 3;
else false
Statement last;
End
121
Conditional Constructs in Java 121

