编写java程序,要求在当前日期的前100个星期中,打印号数和星期数都与今天相同的日期

2024-11-26 04:37:18
推荐回答(2个)
回答1:

Calendar calendar = Calendar.getInstance();
int week = calendar.get(Calendar.DAY_OF_WEEK);// 当前星期几
int days = calendar.get(Calendar.DAY_OF_MONTH);// 当前日期
for (int i = 0; i < 100 * 7; i++) {
calendar.add(Calendar.DAY_OF_YEAR, -1);
if (calendar.get(Calendar.DAY_OF_WEEK) == week
&& calendar.get(Calendar.DAY_OF_MONTH) == days) {

System.out.println(calendar.get(Calendar.YEAR) + ":"
+ (calendar.get(Calendar.MONTH) + 1) + ":"
+ calendar.get(Calendar.DAY_OF_MONTH));
}
}
}

回答2:

学习了