Write code to fill String Zero from left
//package com.book2s; public class Main { public static void main(String[] argv) { String str = "book2s.com"; int len = 42; System.out.println(StringFillLeftZero(str, len)); }/*from www . j a va2 s. co m*/ public static String StringFillLeftZero(String str, int len) { if (str.length() < len) { StringBuffer sb = new StringBuffer(len); for (int i = 0; i < len - str.length(); i++) sb.append('0'); sb.append(str); return new String(sb); } else return str; } }