Here you can find the source of addLeadingZeros(String s, int nZeros)
private static String addLeadingZeros(String s, int nZeros)
//package com.java2s; /******************************************************************************* * Copyright (c) 2007, 2008 Tran Nam Quang. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://from www. j a v a2 s . co m * Tran Nam Quang - initial API and implementation *******************************************************************************/ public class Main { /** * Prepends <tt>nZeros</tt> zeros to the given string and returns the * resulting string. */ private static String addLeadingZeros(String s, int nZeros) { char[] zeros = new char[nZeros]; for (int i = 0; i < zeros.length; i++) zeros[i] = '0'; return String.valueOf(zeros) + s; } }