DEV Community

özkan pakdil
özkan pakdil

Posted on

Human Readable Time

Write a function, which takes a non-negative integer (seconds) as input and returns the time in a human-readable format (HH:MM:SS)

HH = hours, padded to 2 digits, range: 00 - 99
MM = minutes, padded to 2 digits, range: 00 - 59
SS = seconds, padded to 2 digits, range: 00 - 59
Enter fullscreen mode Exit fullscreen mode

The maximum time never exceeds 359999 (99:59:59)

You can find some examples in the test fixtures.

solution in java

public static String makeReadable(int seconds) {
    int minutes=seconds/60;
    int hour=minutes/60;
    return String.format("%02d:%02d:%02d",hour,minutes%60,seconds%60);
  }
Enter fullscreen mode Exit fullscreen mode

Reference:https://www.codewars.com/kata/52685f7382004e774f0001f7/java

Top comments (0)