-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeCalc1.java
More file actions
31 lines (24 loc) · 990 Bytes
/
TimeCalc1.java
File metadata and controls
31 lines (24 loc) · 990 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
* Time Calculation I
Write a program (TimeCalc1) that reads three integers representing a time duration in hours, minutes, and seconds, and prints the equivalent time duration in seconds. Here is a typical run- time example of this program (the user's input is underlined; everything else is generated by the program):
Enter hours: 2
Enter minutes: 28
Enter seconds: 42
This time duration lasts 8922 seconds.
*/
import java.util.Scanner;
public class TimeCalc1 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
// Get the user's input
System.out.print("Enter hours: ");
int hours = scan.nextInt();
System.out.print("Enter minutes: ");
int minutes = scan.nextInt();
System.out.print("Enter seconds: ");
int seconds = scan.nextInt();
int sumInSeconds = hours * 60 * 60 + minutes * 60 + seconds;
System.out.println("This time duration lasts " + sumInSeconds + " seconds.");
scan.close();
}
}