Guest User

Untitled

a guest
Jan 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. public class Clock {
  2.     public static void main(String [] args ) {
  3.         final int DAYS_IN_WEEK = 7;
  4.         final int HOURS_IN_DAY = 24;
  5.         final int MINUTES_IN_HOUR = 60;
  6.         final int SECONDS_IN_MINUTE = 60;
  7.         final int SECONDS_IN_HOUR = MINUTES_IN_HOUR * SECONDS_IN_MINUTE;
  8.         final int SECONDS_IN_DAY = HOURS_IN_DAY * MINUTES_IN_HOUR * SECONDS_IN_MINUTE;
  9.        
  10.         final int totalSeconds = SECONDS_IN_DAY;
  11.        
  12.         // start the clock
  13.         for (int currentSeconds = 0; currentSeconds <= totalSeconds; currentSeconds++) {
  14.             // calculate what the values are the moment in clock
  15.             int numOfDays = currentSeconds / SECONDS_IN_DAY % DAYS_IN_WEEK;
  16.             int numOfHours = currentSeconds % SECONDS_IN_DAY / SECONDS_IN_HOUR % HOURS_IN_DAY;
  17.             int numOfMinutes = currentSeconds % SECONDS_IN_HOUR / SECONDS_IN_MINUTE % MINUTES_IN_HOUR;
  18.             int numOfSeconds = currentSeconds % SECONDS_IN_MINUTE;
  19.             // print the current times on the clock
  20.             System.out.println(numOfDays + ":" + numOfHours + ":" + numOfMinutes + ":" + numOfSeconds);
  21.         }
  22.     }
  23. }
Add Comment
Please, Sign In to add comment