Monday, January 16, 2017

Think Java - Chapter 2 Exercise 2.3: My Finished Code


public class Time {

public static void main(String[] args) {
int hoursInDay = 24;
int minutesInHour = 60;
int secondsInHour = 60;

int currentHour = 17;
int currentMinute = 38;
int currentSecond = 30;

if (currentMinute > 0 | currentSecond > 0) {
currentHour = currentHour + 1;
}

int hourCountdown = hoursInDay - currentHour;
int minuteCountdown = minutesInHour - currentMinute;
int secondCountdown = secondsInHour - currentSecond;

if (currentMinute <= 0) {
minuteCountdown = 0;
}

if (currentSecond <= 0) {
secondCountdown = 0;
}

System.out.println(hourCountdown + " hours " + minuteCountdown + " minutes and " + secondCountdown
+ " seconds remaining today.");

}

}

No comments:

Post a Comment