Seconds to h:m:s
Completed
Read a number of seconds and print it as H:MM:SS (minutes and seconds with two digits).
Input
One non-negative integer.
Output
For 3725 the output is 1:02:05.
Example
Input
3725
Output
1:02:05
Editor
Java
Hints
%02d pads a number with a leading zero to 2 digits.
Solution explanation
Combining / and % splits a quantity into units.
Show solution
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int total = sc.nextInt();
int hours = total / 3600;
int minutes = total % 3600 / 60;
int seconds = total % 60;
System.out.printf("%d:%02d:%02d%n", hours, minutes, seconds);
}
}