Ask Question
4 February, 10:34

Write a java program that prompts the user to input the elapsed time for an event in hours, minutes, and seconds. The program then outputs the elapsed time in seconds.

+1
Answers (1)
  1. 4 February, 11:40
    0
    import java. util.*;

    class seconds

    {

    public static void main (String[] args)

    {

    Scanner takeinput=new Scanner (System. in); //creating a scanner object for taking input.

    int hour, min, sec; / /declaring 3 variables for hour, minutes and seconds.

    System. out. println ("enter hours");

    hour=takeinput. nextInt (); //taking input of hours ...

    System. out. println ("enter minutes");

    min=takeinput. nextInt (); //taking input of minutes ...

    System. out. println ("enter seconds");

    sec=takeinput. nextInt (); //taking input of seconds ...

    int tot_time_sec = (hour*60*60) + (min*60) + sec; / /calculating time in seconds in variable tot_time_sec.

    System. out. println ("Total time in seconds is "+tot_time_sec); //pritning total time in seconds ...

    }

    }

    For input:

    7

    20

    45

    Output is:-

    Total time in seconds is 26445 ...

    Explanation:

    Above is the code for finding the time in seconds. I have taken three integer variables hour, min and sec for taking input of hours, minutes and seconds. After taking input i have taken an integer variable tot_time_sec to store the calculated time in seconds and after that printing tot_time_sec.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a java program that prompts the user to input the elapsed time for an event in hours, minutes, and seconds. The program then outputs ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers