mitsuba-renderer / mitsuba2

Mitsuba 2: A Retargetable Forward and Inverse Renderer
Other
2.05k stars 266 forks source link

用java或C++用物件導向的概念設計程式解下面的問題:讀取一組時間,計算出時針與分針的夾角,時間的格式是0:00到12:00,小時數可能為1或2位數,分鐘數總是2位數,00到59之間。輸出腳讀為0到180之間的值,角度的精確度到千分之一。例如9:00是90.000度,不是-90,也不是270,2:00則是60 #637

Closed Shy-fawn closed 1 year ago

Shy-fawn commented 1 year ago

class ClockAngle { private int hour; private int minute;

public ClockAngle(int hour, int minute) {
    this.hour = hour;
    this.minute = minute;
}

public double calculateAngle() {
    double hourAngle = (hour + (minute / 60.0)) * 30;
    double minuteAngle = minute * 6;
    double angle = Math.abs(hourAngle - minuteAngle);
    return angle > 180 ? 360 - angle : angle;
}

}

public class Main { public static void main(String[] args) { ClockAngle angle = new ClockAngle(9, 0); System.out.println(angle.calculateAngle()); } }

njroussel commented 1 year ago

Hi @Shy-fawn

This has nothing to do with mitsuba2. I will close this issue.