?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Moderate

Array Printing Using Strings (Liquids)

APCSA-E6TNJ5

Consider the following code segment.

    String[] liquids = {"milk", "soda", "water", "tea", "eggnog"};
    String chars = "";

    for (int i=0; i<liquids.length; i++)
    {
        int x = liquids[i].length()/2;
        chars += liquids [i].substring(x, x+1);
    }
    System.out.println(chars);

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

A

ldten

B

lkdateeano

C

lkdatereanog

D

msaee

E

A StringIndexOutOfBoundsException is thrown