?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Easy

Looping Through a String and Printing Characters

APCSA-BXN3YW

Consider the following code segment.

String animal = "coyote";
for (int i=0; i<animal.length(); i++)
{
    if (animal.substring(i,i+1).equals("o"))   
        System.out.println(animal.substring(i,i+1));
    else
        System.out.print(animal.substring(i,i+1));
}

What is printed as a result of executing the code segment?

A
coyote
B
c
o
y
o
t
e
C
c
oy
ot
e
D
co
yo
te
E
c
o
y
o
te