Skip to content

Instantly share code, notes, and snippets.

@andymuncey
Last active October 24, 2023 15:39
Show Gist options
  • Save andymuncey/f5514776aea2ea9716b4cd6d66d3c4a2 to your computer and use it in GitHub Desktop.
Save andymuncey/f5514776aea2ea9716b4cd6d66d3c4a2 to your computer and use it in GitHub Desktop.
for (int i = 0; i <24; i++){ //counter for 24 hour clock
String suffix = ":00";
//suffix changes to pm from 12 onwards
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