?

Free Version

Upgrade subject to access all content

Difficult

Printing Animals in If/Else Conditional Statements

APCSA-GVG2YE

Consider the following poorly formatted method.

public static void animals(int x)
{
    if (x < -3)
        System.out.println("cat");
    else if (x < 1)
        System.out.print("dog");
        System.out.println("snake");
    else if (x != 0){
        System.out.println("bird"); }
    else
        System.out.println("frog");
        System.out.print("turtle");
    if (x > 2)
        System.out.println("fish");
    else
    System.out.println("mouse");
}

What is printed when the following code segment is executed from some other method in the same class?

for(int i = -1; i <2; i++)
    animals(i);
A

dogturtlemouse
dogturtlemouse
bird
turtlemouse

B

dog-snake
turtle-mouse
dog-snake
turtle-mouse
bird
turtle-mouse

C

dog-snake
turtle-mouse
dog-snake
turtle-mouse
snake
bird
turtle-mouse

D

dog-snake
bird
turtle-mouse
dog-snake
frog
turtle-mouse
snake
bird
turtle-mouse

E

Nothing is printed because of a syntax error.