하루 동안 경과 한 시간의 백분율을 찾으려고 시도합니다. 내가 뭘 잘못하고 있는지 모르겠지만 코드를 컴파일하고 실행하면 0.0이 나오고 내가 잘못했는지 확실하지 않습니다.하루의 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 분할. –
코드를 모두 보지 않았지만 int로 나뉘어져있는 것을 볼 수 있습니다. percentageOfDayElapsed = (double) secondsElapsed/(double) secondsPerDay; – TungstenX