Computer Applications

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)

Java

Input in Java

89 Likes

Answer

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

Answered By

34 Likes


Related Questions