0 is added but not shown as two digit when converted to int
I want to add a 0
in front of a date if it is single digit. So I made a code:
public class Zero {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String zero="0";
Calendar cal = new GregorianCalendar();
int day1 = cal.get(Calendar.DAY_OF_MONTH);
String seven1=Integer.toString(day1);
System.out.println(""+seven1);
System.out.println(""+day1);
String added=zero.concat(seven1);
System.out.println(""+added);
int change=Integer.parseInt(added);
System.out.println(""+change);
}
}
So when I print change
it prints only 7
not 07
. Actually I want to make the int
07
instead of 7
. So what modification should be done to print 07
?
NB- I did not mention the if-else
checking for single-digit or multi-digit date intentionally as there is no problem with it!