Limited access

Upgrade to access all content for this subject

Consider the following code segment.

String veggy = "carrot"; 
String str1 = "";
String str2 = "";

for (int i=0; i<veggy.length(); i++)
{
    str1 = str1 + veggy.substring(i, i+1);
    str2 = veggy.substring (i, i+1) + str2;
}
if (str1.compareTo(str2)<0)
    System.out.println(str1 + " < " + str2);
else
if (str1.compareTo(str2)==0)
    System.out.println(str1 + " = " + str2);
else
    System.out.println(str1 + " > " + str2);

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

A
torrac > carrot
B
carrot = carrot
C
torrac = torrac
D
carrot < torrac
E
torrac < carrot
Select an assignment template