Page 192 - ComputerScience_Class_11
P. 192
if(Condition3)
{
Statement3;
}
else
{
Statement4;
}
}
Flowchart:
True False
Condition 1
True False True False
Condition 2 Condition 3
Statement 1 Statement 2 Statement 3 Statement 4
For example:
if(a>b)
{
if(a>c)
{
max=a;
}
else
{
max=c;
}
}
else
{
if(b>c)
{
max=b;
}
else
{
max=c;
}
}
Here, among the three numbers, the greatest number is to be found. For this, the nested if statement is used. If the
value of ‘a’ is greater than the value of ‘b’, then the inner code will be checked to find out the greater of a and c and
the variable ‘max’ is assigned the value accordingly. On the other hand, if the outermost (first) condition which checks
the greater of a and b is false, then the inner if statement under the else part will be checked and the variable ‘max’
is assigned the value accordingly.
Ternary Operator
The ternary operator in Java is a concise way of performing conditional operations. It is the only operator in Java that
takes three operands. It is often used as a shorthand for an if-else statement.
190 Touchpad Computer Science (Ver. 3.0)-XI

