The output of the statements is
1
-31
32
0
The fi rst int displayed from line 8 is positive because the string “ hello ” is greater than
“ goodbye “ . The actual value of the positive number is normally irrelevant, and for String
objects it represents the difference between the fi rst unequal characters between the two
strings. Line 9 compares “ Hello ” to “ goodbye ” and outputs - 31 because H is uppercase and
appears before all lowercase letters. Therefore, “ Hello ” is less than “ goodbye “ . Similarly,
“ hello ” is greater than “ Hello ” on line 10, which outputs 32 . Line 11 outputs 0 because
the two strings are equal
From:
Sun Certified Programmer
for Java® Platform, SE6