Clock Simulation

From CompSciWiki
Revision as of 11:51, 11 April 2010 by ChristopherJ (Talk | contribs)

Jump to: navigation, search

Back to the Program-A-Day homepage

Problem

Write a program that will display every second in a 24 hour clock time cycle. Make the output in the format:

00:00:01
00:00:02
00:00:03

Warning: As with many other problems done with nested loops, this program should take some time to execute. It will not print everything instantly.

 

...by Students

Nested loops are probably one of the worst tools to use in terms of performance. If you end up taking Analysis of Algorithms and future classes in performance you will understand how much of a time waster nested loops can be. As you will see in the problem I have presented here there are 3 potential loop structures. Hours loops 24 times, minutes 60 times, and seconds 60 times. Your computer will print the time message 24*60*60 = 86,400 times. Which, when your processor can handle billons of operations, is not that much. But for Java, it can take a couple seconds. If you're into that sort of thing, I encourage you to continue in computer science. If your not interested in performance (as I am) there are still many more areas of computer science to explore. Find out more at www.cs.umanitoba.ca.

Solution

Code

Solution Code

Back to the Program-A-Day homepage