Untitled

mail@pastecode.io avatar
unknown
java
7 months ago
654 B
0
Indexable
Never
public class ClockAngleCalculator {
    public static void main(String[] args) {
        // Example usage:
        double result = findMinAngle(3, 0);
        System.out.printf("%.1f\n", result);

        result = findMinAngle(8, 6);
        System.out.printf("%.1f\n", result);
    }

    public static double findMinAngle(int hour, int minute) {
        double minuteAngle = minute * 6;
        double hourAngle = (hour % 12) * 30 + (minute / 60.0) * 30;
        double angleDifference = Math.abs(hourAngle - minuteAngle);
        double minAngle = Math.min(360 - angleDifference, angleDifference);

        return minAngle;
    }
}