Advertisements
Advertisements
Question
Write a program to input time in seconds. Display the time after converting them into hours, minutes and seconds.
Sample Input: Time in seconds: 5420
Sample Output: 1 Hour 30 Minutes 20 Seconds
Answer in Brief
Solution
import java.util.*;
public class U5_Q4
{public static void main(String ag[])
{Scanner obj = new Scanner(System.in);
int tsec, hr, min, sec, rem;
tsec = obj.nextlnt();
hr = tsec / 3600;
rem = tsec % 3600; // % gives remainder of tsec / 3600
min = rem / 60;
sec = rem % 60;
System.out.println{hr + " Hour(s), " + min + " Minute(s), " + sec + " Second(s)");
}}
shaalaa.com
Is there an error in this question or solution?