ICSE Class 10 Computer Applications
Question 20 of 32
Input in Java — Question 20
Back to all questions 20
Question Question 20
Write a program in Java that accepts the seconds as input and converts them into the corresponding number of hours, minutes and seconds. A sample output is shown below:
Enter Total Seconds:
5000
1 Hour(s) 23 Minute(s) 20 Second(s)
import java.util.Scanner;
public class KboatTimeConvert
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter time in seconds: ");
long secs = in.nextLong();
long hrs = secs / 3600;
secs %= 3600;
long mins = secs / 60;
secs %= 60;
System.out.println(hrs + " Hour(s) " + mins
+ " Minute(s) " + secs + " Second(s)");
in.close();
}
}Output
