Last active
May 12, 2022 22:29
-
-
Save khatchad/5288272bc7807c373998 to your computer and use it in GitHub Desktop.
This program uses nested loops to simulate a clock.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
This program uses nested loops to simulate a clock. | |
*/ | |
public class Clock | |
{ | |
public static void main(String[] args) | |
{ | |
//Always show two digits. | |
DecimalFormat formatter = new DecimalFormat("00"); | |
// Simulate the clock. | |
for (int hours = 1; hours <= 12; hours++) | |
{ | |
for (int minutes = 0; minutes <= 59; minutes++) | |
{ | |
for (int seconds = 0; seconds <= 59; seconds++) | |
{ | |
System.out.println(formatter.format(hours) + ":" + | |
formatter.format(minutes) + ":" + | |
formatter.format(seconds)); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment