Ask Question
30 July, 11:39

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.

+3
Answers (1)
  1. 30 July, 13:52
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers