Write code to pad long with zero and return as a String
//package com.book2s; import java.text.DecimalFormat; public class Main { public static void main(String[] argv) { long val = 42; int len = 4; System.out.println(long2StringLeftZero(val, len)); }//from w ww . j a v a2 s.c om public static String long2StringLeftZero(long val, int len) { String pattern = ""; for (int i = 0; i < len; i++) pattern += '0'; DecimalFormat fmt = new DecimalFormat(pattern); return fmt.format(val); } }