Here you can find the source of formatNumberWithSameWidth(int d)
public static String formatNumberWithSameWidth(int d)
//package com.java2s; public class Main { public static String formatNumberWithSameWidth(int d) { return formatNumberWithSameWidth(d, String.valueOf(d).length()); }// w ww . j a va 2s .c om public static String formatNumberWithSameWidth(int d, int width) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < width; i++) { sb.append("0"); } sb.append(d); String s = sb.toString(); return s.substring(s.length() - width); } }