Seconds to H M S
Mediumjava
Learn the Concept: Arithmetic OperatorsRead a whole number of seconds and break it into hours, minutes and seconds using / and %.
Input: one non-negative integer — a number of seconds.
Output: one line: <h>h <m>m <s>s
Example 1
Input
3661
Output
1h 1m 1s
- 0 <= seconds <= 1000000
Hint 1
hours = total / 3600; remaining = total % 3600.
Hint 2
minutes = remaining / 60; seconds = remaining % 60.
Integer division by 3600 gives whole hours; the remainder (% 3600) is the leftover seconds, which you split again by 60 for minutes and seconds. This is the classic use of / and % together.
Submit an attempt to unlock the solution. (Sign in first.)
Related Problems
- Five Arithmetic ResultsEasy · javaSolve Problem
- Average of Two IntegersEasy · javaSolve Problem
- Last Digit and the RestEasy · javaSolve Problem