How to add leading zeros to a number?
This example shows you how to use the String.format() method to add zero padding to a number. If you just want to print out the result you can use System.out.format(). This method is available since Java 1.5, so If you use a previous version you can use the NumberFormat class, see: How to format a number with leading zeros?.
For more information about the format syntax you can find it here.