Ask Question
12 December, 04:16

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.

+2
Answers (1)
  1. 12 December, 04:44
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers