展开全部
不用Calendar 和Date 会比较麻烦,给你个例子看看吧public class $ {
private static int[] DAYS = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
public static void main(String[] args) {
System.out.println(test(50, 5));
}
private static int test(int years, int weeks) {
try {
int count = 0;
int week = 1;
for (int i = 1900; i <= 1900 + years; i++) {
for (int j = 1; j <= 12; j++) {
int day = getDay(i, j);
for (int k = 1; k <= day; k++) {
if (i == 1900 + years && j == 1 && k == 1) {
return count;
}
if (k !32313133353236313431303231363533e59b9ee7ad9431333332626639= 13) {
continue;
}
if (week == weeks) {
System.out.println(i + "-" + j + "-" + k + ",星期" + week);
count++;
}
week++;
if (week == 6) {
week = 0;
}
}
}
}
return count;
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
private static int getDay(int year, int month) {
if (!runnian(year)) {
return DAYS[month - 1];
}
return month == 2 ? 29 : 28;
}
private static boolean runnian(int year) {
return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
}
}