Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static String formatShortDuration(int seconds) {
        int hours = seconds / 3600;
        int minutes = (seconds % 3600) / 60;
        int secondRemainder = seconds % 60;
        StringBuilder sb = new StringBuilder();
        if (hours > 0) {
            sb.append(hours);
            sb.append(":");
        }
        if (minutes < 10)
            sb.append('0');
        sb.append(minutes);
        sb.append(":");
        if (secondRemainder < 10)
            sb.append('0');
        sb.append(secondRemainder);

        return sb.toString();
    }
}