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;

Respuesta :

Answer:

return 8 * x;

Explanation:

Required

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

We have, on the first line:

[tex]x=>x +x[/tex]

[tex]x=>2x[/tex]

On the second line:

[tex]x=>x +x[/tex]

[tex]x=>2x[/tex]

Recall that, the result of line 1 is: [tex]x=>2x[/tex]

So, we have:

[tex]x=>2 * 2x[/tex]

[tex]x=>4x[/tex] --- at the end of [tex]line\ 2[/tex]

On the third line:

[tex]x=>x +x[/tex]

[tex]x=>2x[/tex]

Recall that, the result of line 2 is: [tex]x=>4x[/tex]

So, we have:

[tex]x = 2 * 4x[/tex]

[tex]x => 8x[/tex]

So: 8 * x can be used

ACCESS MORE
EDU ACCESS
Universidad de Mexico