JAVA设置2000个对象,JAVA--封装一类对象,功能是随机产生一个2000年后的年份,并输出该年2月的日历页,需处理闰年的问题...

Test.java

package com.liu;

public class Test {

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

Calendar_copy calendar = new Calendar_copy();

}

}

Calendar_copy.java

package com.liu;

import java.util.*;

public class Calendar_copy {

public Calendar_copy() {

// TODO Auto-generated constructor stub

int in = (int) (Math.random() * 1000) + 2000;

int mon = 29;

if (in % 4 == 0 && in % 100 != 0 && in % 400 == 0)

mon = 28;

System.out.println(in + "年2月的日历项为:");

System.out.println(" 日 一 二 三 四 五 六 ");

Calendar calendar = Calendar.getInstance();

calendar.set(in, 2, 1);

int week = calendar.get(Calendar.DAY_OF_WEEK) - 1;

String a[] = new String[week + mon];

for (int i = 0; i < week; i++) {

a[i] = "**";

}

for (int i = week, n = 1; i < week + mon; i++) {

if (n <= 9) {

a[i] = String.valueOf(n) + " ";

} else {

a[i] = String.valueOf(n);

}

n++;

}

for (int i = 0; i < a.length; i++) {

if (i % 7 == 0) {

System.out.println("");

}

System.out.print(" " + a[i]);

}

}

}

运行结果:

2385年2月的日历项为:

日   一   二    三   四    五   六

**    **    **    **    **     1     2  3     4     5      6     7     8     9 10   11  12   13   14   15  16 17   18  19   20   21   22  23 24   25  26   27   28   29

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值