Last active
August 19, 2021 08:19
-
-
Save daanta-real/d8c9d28a43b242e6bd4ee010fa738e1e to your computer and use it in GitHub Desktop.
How to get the season number (0 ~ 3) from a month number (1 ~ 12) - only for the north hemisphere
This file contains hidden or 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
// What you need to input: a month number (1~12) | |
// What you will get: 0 is winter, 1 is spring, 2 is summer, 3 is autumn | |
private static String getSeasonName(int m) { return new String[]{ "Winter", "Spring", "Summer", "Autumn" }[m / 3 % 4]; } | |
// Let's convert each month number to the season string | |
for(int m = 1; m <= 12; m++) System.out.printf("%2d → %s", i, getSeasonName(m) + "\n"); | |
/* | |
[[result]] | |
1 → Winter | |
2 → Winter | |
3 → Spring | |
4 → Spring | |
5 → Spring | |
6 → Summer | |
7 → Summer | |
8 → Summer | |
9 → Autumn | |
10 → Autumn | |
11 → Autumn | |
12 → Winter | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment