533,035 views
9 votes
9 votes
Consider the following static method, calculate.

public static int calculate(int x)
{
x = x + x;
x = x + x;
x = x + x;

return x;
}
Which of the following can be used to replace the body of calculate so that the modified version of calculate will return the same result as the original version for all values of x?

return 8 * x;
return 3 + x;
return 3 * x;
return 6 * x;
return 4 * x;

User Adnan Toky
by
3.5k points

1 Answer

16 votes
16 votes

Answer:

return 8 * x;

Step-by-step explanation:

Required

What can replace the three lines of x = x + x

We have, on the first line:


x=>x +x


x=>2x

On the second line:


x=>x +x


x=>2x

Recall that, the result of line 1 is:
x=>2x

So, we have:


x=>2 * 2x


x=>4x --- at the end of
line\ 2

On the third line:


x=>x +x


x=>2x

Recall that, the result of line 2 is:
x=>4x

So, we have:


x = 2 * 4x


x => 8x

So: 8 * x can be used

User Robert Navado
by
2.6k points