forked from AllenDowney/ThinkJavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConvertTime.java
More file actions
27 lines (18 loc) · 761 Bytes
/
Copy pathConvertTime.java
File metadata and controls
27 lines (18 loc) · 761 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
import java.util.Scanner;
public class ConvertTime
{
public static void main(String[] args) {
int secondsIn;
Scanner in = new Scanner(System.in);
// prompt the user and get the value
System.out.print("Exactly how many seconds? ");
secondsIn = in.nextInt();
final int SECONDS_PER_HOUR = 60 * 60;
int hours = secondsIn / SECONDS_PER_HOUR;
final int SECONDS_PER_MINUTE = 60;
int minutes = (secondsIn - (hours * SECONDS_PER_HOUR)) / SECONDS_PER_MINUTE;
int seconds = (secondsIn - (hours * SECONDS_PER_HOUR)) % SECONDS_PER_MINUTE;
System.out.printf(secondsIn + " seconds = %d hours, %d minutes, and %d seconds.\n",
hours, minutes, seconds);
}
}