Limited access

Upgrade to access all content for this subject

Consider the following method.

public static String constructString(ArrayList<String> words)
{
    String s = "";
    for (int i=words.size()-1; i>=0; i--)
    {
        String a = words.get(i).substring(0,1);
        String b = words.get(i).substring(words.get(i).length()-1);

        if (a.equals(b))
        s+="ZZ";
        else
        s+=b+a;
    }
    return s;
}

What is the output after executing the following segment of code?

ArrayList<String> words = new ArrayList<String>();
words.add("dragon");
words.add("snakes");
words.add("worm");
words.add("pup");
words.add("antelope");
words.add("goat");
System.out.println(constructString(words));
A

tgeappmwssnd

B

gtaeZZwmZZdn

C

ndZZmwZZeatg

D

dnZZwmZZaegt

E

tgeaZZmwZZnd

Select an assignment template