/********************************************************************* * Author: Eric Heim * Date Created: 6/9/2011 * Course: CS0007 * Description: Shows the use of nested loops to display a clock *********************************************************************/ import java.text.DecimalFormat; public class NestedLoop { public static void main(String[] args) { DecimalFormat formatter = new DecimalFormat("00"); for(int hour = 0; hour < 24; hour++) { for(int minute = 0; minute < 60; minute++) { for(int second = 0; second < 60; second++) { System.out.println(formatter.format(hour) + ":" + formatter.format(minute) + ":" + formatter.format(second)); //Simply sleeps for 1 second try{ Thread.sleep(1000); } catch(InterruptedException ie){} } } } } }