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
34 lines (24 loc) · 919 Bytes
/
Copy pathConvertTime.java
File metadata and controls
34 lines (24 loc) · 919 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
32
33
//Exercise 3-3.
import java.util.Scanner;
public class ConvertTime
{
public static void main(String[] args)
{
int inputSeconds;
int numberHours;
int numberMinutes;
int numberSeconds;
Scanner in = new Scanner(System.in);
// prompt the user and get the value
System.out.print("What is the number of seconds? ");
inputSeconds = in.nextInt();
// convert and output the result
numberSeconds = inputSeconds % 60;
System.out.println(numberSeconds);
numberMinutes = ((inputSeconds - numberSeconds) / 60) % 60;
System.out.println(numberMinutes);
numberHours = ((inputSeconds - numberSeconds) / 60) / 60;
System.out.println(numberHours);
System.out.println(inputSeconds + " seconds = " + numberHours + " hours, " + numberMinutes + " minutes, " + numberSeconds + " seconds");
}
}