我有一个日历,我已经设法在一个月内打印所有日子。我现在想摆脱或更改我的代码,以便它排除周末,因为它将是一个rota而没有人在周末工作。我不确定如何做到这一点,我的想法建议一个if循环,但已经尝试过,我不确定。
我的代码:
public static String[] teamJedi = {"Andrew", "Sanjay", "Austen"};
public static void main(String[] args) {
Calendar calendar = Calendar.getInstance();
if (args.length == 2) {
int year = Integer.parseInt(args[0]);
int month = Integer.parseInt(args[1]);
calendar.set(year, month, 1);
}
int month = calendar.get(Calendar.MONTH);
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
int teamSize = teamJedi.length;
int counter = 0;
while (calendar.get(Calendar.MONDAY) == month) {
System.out.println(calendar.getTime());
System.out.println(teamJedi[counter++ % 3]);
calendar.add(Calendar.DATE, 1);
}
}
答案 0 :(得分:0)
只需使用
calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
检查当天是星期六,星期日是否相同