?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Moderate

Conditional Execution With Nested If Statements

APCSA-KKASEW

Consider the following method.

public static int nested(int x, int y)
{
    int q = 0;

    if (x == 1) 
    {
        q++;
        if (y == 2)
            q++;
        y++;
    }
    q++;
    if (y == 3) 
    {
        q++;
        if (y == 2) 
        {
            q++;
            q++;
        }
    }
    q++;
    return q;
}

Which of the following is returned as a result of the call nested(1, 2)?

A

1

B

2

C

3

D

4

E

5