試圖找出一天中過去的時間百分比。我不知道我在做什麼錯,但編譯和執行代碼只是給我0.0,我不知道我做錯了什麼。已過去時間的百分比(Java)
class Time {
public static void main(String[] args) {
// variable assignments apply to the time when I started
// writing program
int hour, minute, second;
hour = 11;
minute = 8;
second = 14;
int hoursToMinutes = hour * 60;
int minutesToSeconds = (hoursToMinutes + minute) * 60;
int secondsElapsed = minutesToSeconds;
System.out.println(secondsElapsed + " seconds have elapsed.");
int secondsPerDay = 24 * 60 * 60;
double percentageOfDayElapsed = secondsElapsed/secondsPerDay;
System.out.println(secondsPerDay);
System.out.println(percentageOfDayElapsed + "% of the day has elapsed.");
}
}
INT除法代替浮點。 – 2014-12-07 16:21:22
我沒有看過你的所有代碼,但我看到你用int分開,試試double percentOfDayElapsed =(double)secondsElapsed /(double)secondsPerDay; – TungstenX 2014-12-07 16:22:39