public static void main(String[] args) {
int year =2021;
Calendar calendar=new GregorianCalendar(year,0,1);
int i=1;
while(calendar.get(Calendar.YEAR)<year+1){
calendar.set(Calendar.WEEK_OF_YEAR,i++);
calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
if(calendar.get(Calendar.YEAR)==year){
System.out.printf("星期天:%tF%n",calendar);
}
calendar.set(Calendar.DAY_OF_WEEK,Calendar.SATURDAY);
if(calendar.get(Calendar.YEAR)==year){
System.out.printf("星期六:%tF%n",calendar);
}
}
}
网友评论