Answer:
Output
Enter hours:
1
Enter minutes:
28
Enter seconds:
42
The total seconds is 5322
Explanation:
Below is the java program that reads integers representing a time duration in hours, minutes, and seconds, and then prints the equivalent total number of seconds.
import java.util.Scanner;
public class TimeConverter {
public static void main(String[] args){
int hour=0,min=0,sec=0;
Scanner input=new Scanner(System.in);
System.out.println("Enter hours: ");
hour=input.nextInt();
System.out.println("Enter minutes: ");
min=input.nextInt();
System.out.println("Enter seconds: ");
sec=input.nextInt();
int hourToSec=hour*60*60; //convert hours to seconds
int minToSec=min*60; //convert minutes to seconds
int totalSeconds=hourToSec+minToSec+sec; //calculate total seconds
System.out.println("The total seconds is "+totalSeconds);
}
}