Skip to content

Instantly share code, notes, and snippets.

@guntaka
Created June 21, 2021 03:25
Show Gist options
  • Save guntaka/568a62c5c7ef0b3e71932b674c9a7161 to your computer and use it in GitHub Desktop.
Save guntaka/568a62c5c7ef0b3e71932b674c9a7161 to your computer and use it in GitHub Desktop.
Generate a string of 4 quarters with starting month input
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