?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Moderate

How Long is Quote from String ArrayList

APCSA-DNANKY

Consider the following code segment.

ArrayList<String> words = // words is not empty and is full of words

String quote = "Quote:";     // includes a space after colon
for (int i=0; i<words.size()-1; i++)
{
    quote += words.get(i) + " ";  // " " is a single space
}
quote += words.get(words.size()-1):

Which of the following formulas would be correct to describe the results of this segment of code?

Assume that:
the words array list is not empty
e = the number of elements in words;
s = the sum of the lengths of the String elements in words;
q = the length of the quote string after the code completes execution;
p = the last position (index) in words

A

q = s + e + 7

B

q = s + e + 6

C

q = s + p - e + 7

D

q = s + e + p - 1

E

q = s + p + e