?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Moderate

Printing Fruit Using If/Else Conditional Statements

APCSA-4JG5WV

Consider the following method.

public static void fruits(int q)
{
    if (q < -2)
        System.out.println("Apple");
    System.out.println("Pear");
    if (q <=-2)
        System.out.println("Orange");
    else
        System.out.println("Banana");
    System.out.println("Grape");
    if (q < 0)
    {
        System.out.println("Blueberry");
        System.out.println("Kiwi");
    }
    else if (q !=2)
        System.out.println("Cantaloupe"); 
    else if (q<3)
        System.out.println("Watermelon");
    else
        System.out.println("Mango");
    if (q = 2 || q > -2)
        System.out.println("Strawberry");
    System.out.println("Cherry");
}

Which of the following is printed as a result of the call fruits(-2)?

A

Orange
Blueberry
Kiwi

B

Pear
Orange
Grape
Blueberry
Kiwi
Cantaloupe
Watermelon

C

Apple
Orange
Grape
Blueberry
Kiwi
Cantaloupe
Watermelon

D

Apple
Orange
Grape
Blueberry
Kiwi
Watermelon
Cherry

E

Pear
Orange
Grape
Blueberry
Kiwi
Cherry