Java examples for Language Basics:Number Format
Printing with the 0 (zero) flag fills in leading zeros.
public class Main { public static void main(String[] args) { /*from w ww . j a v a2 s. com*/ System.out.printf("%+09d\n", 452); System.out.printf("%09d\n", 452); System.out.printf("% 9d\n", 452); } }