Skip to content

Instantly share code, notes, and snippets.

@khatchad
Last active May 12, 2022 22:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khatchad/5288272bc7807c373998 to your computer and use it in GitHub Desktop.
Save khatchad/5288272bc7807c373998 to your computer and use it in GitHub Desktop.
This program uses nested loops to simulate a clock.
/**
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