Limited access

Upgrade to access all content for this subject

Consider the following method.

public static String shiftyString(String s)
{
    String output = "";
    for (int i=0; i<s.length()-1; i+=2)
    {
        String s1 = s.substring(i,i+1);
        String s2 = s.substring(i+1, i+2);
        if (s1.compareTo(s2)>=0)
            output += s2 + s1;
        else
            output += s1 + s2;
        output += "-";
    }
    return output;
}

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

String s = "watermelon rind";
System.out.println(shiftyString(s));
A
aw-at-et-er-mr-em-el-lo-no- n- r-ir-in-dn-
B
aw-et-mr-el-no- r-in-
C
aw-et-mr-el-no- r-in-d -
D
w-a-t-e-r-m-e-l-o-n- -r-i-n-d-
E
wa-te-rm-le-on-r -ni- d-
Select an assignment template