QUESTION IMAGE
Question
- match the conditional expression with the if/else statement that performs the same operation.
a) q = x < y? a + b : x * 2;
b) q = x < y? x * 2 : a + b;
c) x < y? q = 0 : q = 1;
if (x < y)
q = 0;
else
q = 1;
if (x < y)
q = a + b;
else
q = x * 2;
if (x < y)
q = x * 2;
else
q = a + b;
Step1: Analyze the first if - else statement
The first if - else statement is if (x < y) q = 0; else q = 1;. In conditional expression form, it is x < y? q = 0 : q = 1, which matches option C.
Step2: Analyze the second if - else statement
The second if - else statement is if (x < y) q = a + b; else q = x 2;. In conditional expression form, it is q = x < y? a + b : x 2, which matches option A.
Step3: Analyze the third if - else statement
The third if - else statement is if (x < y) q = x 2; else q = a + b;. In conditional expression form, it is q = x < y? x 2 : a + b, which matches option B.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
First blank: C
Second blank: A
Third blank: B