import java.util.*;
public class student
{
public static void main(String[] args)
{
GregorianCalendar d=new GregorianCalendar();
int today=d.get(Calendar.DAY_OF_MONTH);
int month=d.get(Calendar.MONTH);
d.set(Calendar.DAY_OF_MONTH,1);
int weekday=d.get(Calendar.DAY_OF_WEEK);
System.out.println("sun mon tue wed thu fri sat");
for(int i=Calendar.SUNDAY;i<weekday;i++)
System.out.print("");
do
{
int day=d.get(Calendar.DAY_OF_MONTH);
if (day == 1&&weekday!=7)
{
for(int x =0;x<4*(weekday-1);x++) {
System.out.print(" ");
}
}
if(day<10 ) System.out.print(" ");
System.out.print(day);
if(day==today)
System.out.print("* ");
else
System.out.print(" ");
if(weekday==Calendar.SATURDAY )
System.out.println();
d.add(Calendar.DAY_OF_MONTH,1);
weekday=d.get(Calendar.DAY_OF_WEEK);
}
while(d.get(Calendar.MONTH)==month);
}
}
此博客展示了一段Java代码,通过import引入相关包,定义了student类。在main方法中,利用GregorianCalendar类获取日期信息,实现了一个日历打印程序,能输出指定月份的日历,并标记当天日期。
6742

被折叠的 条评论
为什么被折叠?



