Here you can find the source of formatNumber(int number, int zeros)
private static String formatNumber(int number, int zeros)
//package com.java2s; //License from project: Open Source License public class Main { private static String formatNumber(int number, int zeros) { String strZeros = repeatString("0", zeros); String strNumber = Integer.toString(number); return new StringBuilder().append(strZeros.substring(0, zeros - strNumber.length())).append(strNumber) .toString();//from w w w . j av a 2 s. c om } private static String repeatString(String string, int times) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < times; ++i) builder.append(string); return builder.toString(); } }