Need help with calendar algorithm
I am trying to create a gag calendar app and need some help getting the algorithm correct to crea开发者_运维百科te a calendar like this:
Sunday
Jan Feb .. Dec
2 6 4
9 13 11
16 20 18
23 27 25
30
Monday
Jan Feb .. Dec
3 7 5
10 14 12
17 21 19
24 28 26
31
And so on... I have the code from http://helpdesk.objects.com.au/java/display-a-month-as-a-calendar
But can't get the algorithm to do it like above.
Model the desired output as a three-dimensional array
private static final int DAYS_IN_WEEK = 7;
private static final int WEEKS_IN_MONTH = 5;
private static final int MONTHS_IN_YEAR = 12;
Integer dayNumber[DAYS_IN_WEEK][WEEKS_IN_MONTH][MONTHS_IN_YEAR];
Allocate it and fill it using standard Calendar methods that give you the indices, then iterate over it in row-major order to produce the output.
精彩评论