Answer:
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.