Answer:
B. ans = 60; x = 0; y = 50
Explanation:
<em>(i)First format the code properly as follows:</em>
int ans = 35, x = 50, y =50;
if ( x >= y) {
ans = x + 10;
x -=y;
} else {
ans = y + 10;
y += x;
}
<em>(ii) Taking the if statement of the code;</em>
The if statement block is executed if x is greater than or equal to y (x >= y).
Since x=50 and y=50, then the code continues to execute the statement in the block.
In the if block;
(a) the first line is
<em>ans = x + 10. </em>
Since x = 50, substituting for x gives
ans = 50 + 10 = 60
Therefore <em>ans = 60</em>
(b) the second line is
<em>x -= y</em>
This can be re-written as
x = x - y.
This means that the value of x - y is written back into x. Therefore since x = 50 and y = 50, substituting for x and y gives
x = 50 - 50 = 0
Therefore <em>x = 0</em>
(c) the value of y is not changed at all, therefore <em>y = 50</em>
<em />
<em>(iii) Taking the else statement of the code;</em>
Since the if statement of the code has been executed, the else statement is simply skipped.
Therefore the final values of ans, x, y are respectively 60, 0 and 50