开发者

Need help with calendar algorithm

开发者 https://www.devze.com 2023-02-22 00:09 出处:网络
I am trying to create a gag calendar app and need some help getting the algorithm correct to crea开发者_运维百科te a calendar like this:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消