Here you can find the source of intToTwoDigitString(int integer)
Parameter | Description |
---|---|
integer | to convert to three digit string. |
Parameter | Description |
---|---|
IllegalArgumentException | if integer do not fit in. |
public static String intToTwoDigitString(int integer)
//package com.java2s; /*/*from ww w . j a v a 2 s .c o m*/ **************************************************************************** * * * (c) Copyright 2008 ABM-utvikling * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU General Public License as published by the * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * * Public License for more details. http://www.gnu.org/licenses/gpl.html * * * **************************************************************************** */ public class Main { /** * Create two digit string with leading zeros from integer. * * @param integer to convert to three digit string. * @return - integer as two digit String with leading zeros. * @throws IllegalArgumentException if integer do not fit in. */ public static String intToTwoDigitString(int integer) { String number = String.valueOf(integer); int numberLength = number.length(); if (numberLength == 2) { return number; } else if (numberLength == 1) { return "0" + number; } throw new IllegalArgumentException( "intToTwoDigitString: integer does not fit in, integer was: '" + integer + "'"); } }