122k views
5 votes
This must be done using the latest version of Java Software Development Kit. Write a program that reads integers representing a time duration in hours, minutes, and seconds, and then prints the equivalent total number of seconds. [10 points] Output 1: Enter hours: 1 Enter minutes: 28 Enter seconds: 42 The total seconds is 5322

User Sorcy
by
5.3k points

1 Answer

6 votes

Answer:

Output

Enter hours:

1

Enter minutes:

28

Enter seconds:

42

The total seconds is 5322

Step-by-step 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);

}

}

User Elekwent
by
5.4k points