KnowledgeBoat Logo

Computer Applications

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

Java

Input in Java

404 Likes

Answer

import java.util.Scanner;

public class KboatTime
{
    public static void main(String args[]) {
        
        Scanner in = new Scanner(System.in);
        
        System.out.print("Time in seconds: ");
        int inputTime = in.nextInt();
        
        int hrs = inputTime / 3600;
        int mins = (inputTime % 3600) / 60;
        int secs = (inputTime % 3600) % 60;
        
        System.out.println(hrs 
                            + " Hours " 
                            + mins 
                            + " Minutes " 
                            + secs 
                            + " Seconds");
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of 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

Answered By

170 Likes


Related Questions