资源描述:
《java输出日历》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、用java实现在控制台显示系统日历或显示用户手动输入的日历(转)2008-08-1222:37:29
2、分类:JAVA编程
3、标签:
4、字号大中小订阅packagecn.adam.test;importjava.util.Calendar;classGregorianCalendar{/***定义日期变量*/Calendartoday;/***构造方法*/GregorianCalendar(){/***初始化日期变量为今天日期*/today=Calendar.getInstance();}/***显示系统日历的方法*/voiddisplaySystemCalendar(){Syst
5、em.out.println("显示日历");intyear=today.get(Calendar.YEAR);intmonth=today.get(Calendar.MONTH)+1;System.out.println("ttt"+year+"年"+month+"月");System.out.println("t日"+"t一"+"t二"+"t三"+"t四"+"t五"+"t六");intarrayTotalDayOfMonth[]={31,28,31,30,31,30,31,31,30,31,30,31};if((year%4==0&&year%
6、100!=0)
7、
8、year%400==0){arrayTotalDayOfMonth[1]+=1;}intmaxDayOfMonth=0;for(inti=0;i<12;i++){if(month==i+1){maxDayOfMonth=arrayTotalDayOfMonth[i];break;}}today.set(Calendar.DATE,1);intdayOfWeek=today.get(Calendar.DAY_OF_WEEK);switch(dayOfWeek){case1:System.out.print("t"+today.get(Calendar.DAT
9、E));break;case2:System.out.print("tt"+today.get(Calendar.DATE));break;case3:System.out.print("ttt"+today.get(Calendar.DATE));break;case4:System.out.print("tttt"+today.get(Calendar.DATE));break;case5:System.out.print("ttttt"+today.get(Calendar.DATE));break;case6:System.out.prin
10、t("tttttt"+today.get(Calendar.DATE));break;case7:System.out.print("ttttttt"+today.get(Calendar.DATE));System.out.println("");break;}for(intj=2;j<=maxDayOfMonth;j++){today.set(Calendar.DATE,j);if(today.get(Calendar.DAY_OF_WEEK)==7){if(j<10){System.out.print("t"+j);}else{System.
11、out.print("t"+j);}System.out.println("");}elseif(j<10){System.out.print("t"+j);}else{System.out.print("t"+j);}}}/***显示手动日历的方法*@paramargs1int用于接收月份的参数*@paramargs2int用于接收年份的参数*/voiddisplayManualCalendar(intargs1,intargs2){System.out.println("显示日历");intyear=args2;intmonth=args1;System.out
12、.println("ttt"+year+"年"+month+"月");today.set(Calendar.YEAR,year);today.set(Calendar.MONTH,month-1);System.out.println("t日"+"t一"+"t二"+"t三"+"t四"+"t五"+"t六");intarrayTotalDayOfMonth[]={31,28,31,30,31,30,31,31,30,31,30,31};if((year%4==0&&year%100!