ICSE Class 10 Computer Applications Question 7 of 43

Conditional Constructs in Java — Question 7

Back to all questions
7
Question

Question 7

Format the following if statements with indentation:

i. if (x == y) if (x == z) x = 1; else y = 1; else z = 1;

Answer
if (x == y)
    if (x == z)
        x = 1; 
    else 
        y = 1;
else
    z = 1;

ii. if (x == y) {if (y == z) x = 1; y = 2; } else z = 1;

if (x == y)
{
    if (y == z) 
        x = 1; 
    y = 2; 
} 
else 
    z = 1;

iii. if (num1 != num2) {
    if (num2 >= num3) x = 1; y = 2; }
    else {x = 1; if (num1 == num2) z = 3;}

if (num1 != num2)
{
    if (num2 >= num3)
        x = 1; 
    y = 2;
}
else
{
    x = 1;
    if (num1 == num2)
        z = 3; 
}