| preferred AP College board partner for AP classes
AP Computer Science A/Unit 4: Iteration
Start Practice Test
Share
medium Solved by 2 students
While Loop Execution Trace
< Prev
Next >

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.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1hitrishabhatia11 0m 00s 100
#2hadleysmith501 0m 00s -10
#3y.seong202712 3m 44s -134
APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy