Here you can find the source of getTime(int minutes, int seconds)
public static String getTime(int minutes, int seconds)
//package com.java2s; /*/*from ww w. j a v a 2s .co m*/ * Copyright 2009 Yannick Stucki (yannickstucki.com) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * The smallest number with two digits. Everything below has only one digit * and therefore needs to be prepended by a 0 to have two digits. */ private static final int HAS_TWO_DIGITS = 10; /** * Returns a String formatted with minutes and seconds. */ public static String getTime(int minutes, int seconds) { return getTwoDigitNumber(minutes) + ":" + getTwoDigitNumber(seconds); } /** * Returns a string of an integer which is at least two digits long. The first * digit is filled witha 0 if needed. */ private static String getTwoDigitNumber(int number) { return (number < HAS_TWO_DIGITS ? "0" : "") + Integer.toString(number); } }