-
-
Save andymuncey/f5514776aea2ea9716b4cd6d66d3c4a2 to your computer and use it in GitHub Desktop.
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
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