Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Clock {
- public static void main(String [] args ) {
- final int DAYS_IN_WEEK = 7;
- final int HOURS_IN_DAY = 24;
- final int MINUTES_IN_HOUR = 60;
- final int SECONDS_IN_MINUTE = 60;
- final int SECONDS_IN_HOUR = MINUTES_IN_HOUR * SECONDS_IN_MINUTE;
- final int SECONDS_IN_DAY = HOURS_IN_DAY * MINUTES_IN_HOUR * SECONDS_IN_MINUTE;
- final int totalSeconds = SECONDS_IN_DAY;
- // start the clock
- for (int currentSeconds = 0; currentSeconds <= totalSeconds; currentSeconds++) {
- // calculate what the values are the moment in clock
- int numOfDays = currentSeconds / SECONDS_IN_DAY % DAYS_IN_WEEK;
- int numOfHours = currentSeconds % SECONDS_IN_DAY / SECONDS_IN_HOUR % HOURS_IN_DAY;
- int numOfMinutes = currentSeconds % SECONDS_IN_HOUR / SECONDS_IN_MINUTE % MINUTES_IN_HOUR;
- int numOfSeconds = currentSeconds % SECONDS_IN_MINUTE;
- // print the current times on the clock
- System.out.println(numOfDays + ":" + numOfHours + ":" + numOfMinutes + ":" + numOfSeconds);
- }
- }
- }
Add Comment
Please, Sign In to add comment