- 主题
- 3
- 帖子
- 5
- 精华
- 0
- 积分
- 19
- C币
- 8 枚
- 在线时间
- 1 小时
- 注册时间
- 2010-12-24
- 最后登录
- 2011-4-1
- 性别
- 保密

- 主题
- 3
- 帖子
- 5
- C币
- 8 枚
- 在线时间
- 1 小时
|
//显示当前月份的日历
//MyCalender.java
import java.util.*;
public class MyCalender
{
public static void main(String args[])
{ Calendar cal=Calendar.getInstance();
int day,month,year,date;
month=cal.get(Calendar.MONTH)+1;
year=cal.get(Calendar.YEAR);
System.out.println(year+"年"+month+"月");
cal.set(Calendar.DAY_OF_MONTH,1);
date=cal.get(Calendar.DAY_OF_WEEK); //本月1号的位置
System.out.println("周日 周一 周二 周三 周四 周五 周六");
for(int i=1;i<date;i++)System.out.print(" ");
while(cal.get(Calendar.MONTH)==month-1) //输出各日
{ System.out.print(" ");
if((cal.get(Calendar.DAY_OF_MONTH )<10))
System.out.print(" " +cal.get(Calendar.DAY_OF+MONTH)+" ");
else System.out.print (" "+cal.get(Calendar.DAY_OF_MONTH)+"");
if(cal.get(Calendar.DAY_OF_WEEK)==7)
System.out.println();
day=cal.get(Calendar.DAY_OF_MONTH);
day=day+1;
cal.set(Calendar.DAY_OF_MONTH,day);
}
System.out.println();
}
} |
|