?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Easy

Find The Snail in the String Array

APCSA-V1MY4P

Consider the following two declarations.

int k=0;
String[] teams = {"lions", "vikings", "bears", "titans", "packers"};

Which segment of code would print "snail" to the console?

A
for (int i=0; i<teams.length; i++)
{
    System.out.print(teams[i].substring(teams[i].length()-k-1, teams[i].length()-k));
    k++;
}
B
for (int i=0; i<teams.length; i++)
{
    System.out.print(teams[i].substring(teams[i].length()-k, teams[i].length()));
    k++;
}
C
for (int i=teams.length-1; i>=0; i--)
{
    System.out.print(teams[i].substring(teams[i].length()-k-1, teams[i].length()-k));
    k++;
}
D
for (int i=teams.length-1; i>=0; i--)
{
    System.out.print(teams[i].substring(teams[i].length()-k, teams[i].length()));
    k++;
}
E
for (int i=teams.length-1; i>=0; i--)
{
    System.out.print(teams[i].substring(teams[i].length()-k-1));
    k++;
}