Human Readable Time

kata programming

مساله:

تابعی بنویسید که یک عدد صحیح مثبت(ثانیه) را به عنوان ورودی می گیرد و زمان را در قالب قابل خواندن برای انسان باز می گرداند (HH: MM: SS)

HH = ساعت ، دارای 2 رقم ، محدوده: 00 – 99

MM = دقیقه ، به 2 رقم ، محدوده: 00 – 59

SS = ثانیه ، دارای 2 رقم ، محدوده: 00 – 59

حداکثر زمان هرگز از 359999 تجاوز نمی کند (99:59:59)


Description:

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

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

You can find some examples in the test fixtures.


public class HumanReadableTime {
  public static String makeReadable(int seconds) {
    return String.format("%02d:%02d:%02d", seconds / 3600, (seconds / 60) % 60, seconds % 60);
  }
}
public class HumanReadableTime {
    public static String makeReadable(int seconds) {
        int h = seconds/60/60;
        int min = seconds/60%60;
        int sec = seconds%60;
        return String.format("%02d:%02d:%02d",h,min,sec);
    }
}

دیدگاهتان را بنویسید