Here you can find the source of numberWithLeadingZeroes(int n, int totalChars)
public static String numberWithLeadingZeroes(int n, int totalChars)
//package com.java2s; import java.util.Formatter; import java.util.Locale; public class Main { public static String numberWithLeadingZeroes(int n, int totalChars) { Formatter formatter = new Formatter(Locale.US); String suffix = "" + formatter.format("%0" + totalChars + "d", n); formatter.close();//from w w w . j av a 2s.com return suffix; } }