?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Moderate

String compareTo Scenarios

APCSA-4VNZPL

Place either a (negative sign), + (positive sign), or 0 next to each of the following statements to indicate whether the variable that is being assigned has a value that is negative, positive, or zero respectively.

String itemA = "parka", itemB = "Snow skis", itemC = "Snowboard", itemD = "parka2";
String subB = itemB.substring( 1, 4 );

__ int itemCompareAB = itemA.compareTo(itemB);
__ int itemCompareBC = itemB.compareTo(itemC);
__ int itemCompareSub = subB.compareTo("now");
__ int itemCompareAD = itemA.compareTo(itemD);

What are your answers, listing them from top to bottom?

A
+ 
- 
0 
-
B
+ 
- 
0 
+
C
- 
+ 
- 
+
D
+ 
0 
- 
-
E
- 
0 
+ 
-