-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathClockIntersection.java
More file actions
executable file
·36 lines (33 loc) · 1.3 KB
/
Copy pathClockIntersection.java
File metadata and controls
executable file
·36 lines (33 loc) · 1.3 KB
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
34
35
36
import java.time.LocalTime;
public class ClockIntersection {
public static void main(String... args) {
clockIntersections(11, 10);
}
/**
* takes a number of hours and minutes (up to several days), and returns the
* number of times the minute and hour hands of a standard analog clock
* would cross in that period of time, assuming that the clock always starts
* at midnight, with one intersection. The function should also print every
* unique location of the intersections, whether in degrees with precision
* of 2 decimal points, or in a hour:minute:second format.
*
* You don’t have to
* worry about error handling caused by improper inputs.
*
* @param hours
* @param minutes
* @return
*/
public static int clockIntersections(int hours, int minutes) {
LocalTime midnight = LocalTime.MIDNIGHT;
int intersections = 1;
long time = (long) ((12 / 11.0) * 60 * 60);
long timeInSeconds = (hours * 60 + minutes) * 60;
intersections += timeInSeconds / time;
// System.out.println(intersections);
for (int i = 0; i < intersections; i++) {
System.out.println(i + 1 + ". intersection at: " + midnight.plusSeconds(i * time));
}
return intersections;
}
}