Java tutorial
//package com.java2s; public class Main { public static String formatNumber(int number, int length) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < length; i++) { sb.append("0"); } java.text.DecimalFormat format = new java.text.DecimalFormat(sb.toString()); return format.format(number); } }