Your problem is that your '0' char forced to an integer. Since '0' has an ASCII value of 48 , you get 48 + 2 = 50 .
Note that what you are trying to do will not work - you cannot add the leading 0 to month , since month is a number. The leading zero makes sense only in the lowercase representation of the number.
As explained in this answer , here's how to create a null number:
String.format("%02d", month);
source share