Skip to content

Instantly share code, notes, and snippets.

@andymuncey

andymuncey/HoursOfDay.java Secret

Last active Oct 20, 2020
Embed
What would you like to do?
for (int i = 0; i <24; i++){ //counter for 24 hour clock
String suffix = ":00";
if (i < 12){
suffix += "am";
} else {
suffix += "pm";
}
//am - hours are the same as 24 hour clock
int hour = i; //we don't change i as it would mess up the loop
if (i > 12 ){
//pm hours are 12 less than 24 hour clock
hour -= 12;
}
System.out.println(hour + suffix);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment