This week's book giveaway is in the Big Data forum. We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line! See this thread for details.

The answer here is due to the order of operations, in the 2nd case the "".length() is executed first (which == 0) and then the month + 0 is executed, month is 3 so 3 + 0 == 3.

Evaluates as
a. length = (month+"").length();
b. length = (3+"").length();
c. length = ("3").length(); //Gets the length of the String "3"
d. length = 1

Case 2 -

int month = 3;
int length = month+"".length();

Evaluates as
a. length = month+"".length();
b. length = 3+"".length();
c. length = 3 + 0 //Gets the length of the String "" which is 0
d. length = 3