Created
June 21, 2021 03:25
-
-
Save guntaka/568a62c5c7ef0b3e71932b674c9a7161 to your computer and use it in GitHub Desktop.
Generate a string of 4 quarters with starting month input
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
import static java.util.stream.Collectors.joining; | |
import java.util.stream.IntStream; | |
public class QuarterlyMonths { | |
public static String get(int input) { | |
final int offset = (input % 3) == 0 ? 3 : (input % 3); | |
return IntStream.range(0,4).mapToObj(i -> String.format("%02d", i * 3 + offset)).collect(joining()); | |
} | |
//To test the `get` method | |
public static void main(String[] args) { | |
for(int i = 1; i <= 12; i++) { | |
System.out.printf("%2d -> %s\n", i, get(i)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment