While Loop Execution Trace
Consider the following mystery method.
public static int mystery(int n)
{
int x = 1;
int y = 1;
// Point A
while (n > 2)
{
x = x + y;
// Point B
y = x - y;
n--;
}
// Point C
return x;
}
Which of the following statements is true regarding the execution of this method?
A
n will sometimes be greater than 2 at // Point C.
B
x will sometimes be 1 at // Point B.
C
n will always be greater than 2 at // Point B.
D
x will never be 1 at // Point C.
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | hitrishabhatia | 1 | 1 | 0m 00s | 100 |
| #2 | hadleysmith5 | 0 | 1 | 0m 00s | -10 |
| #3 | y.seong2027 | 1 | 2 | 3m 44s | -134 |
APFIVE