# 代码如下

``````class Solution {
public String dayOfTheWeek(int day, int month, int year) {
String[] week = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday","Sunday"};
// 1 ~ 11 月的天数
int[] monthDay = {31,28,31,30,31,30,31,31,30,31,30};
//年份与底线年份 相差天数
int days = 365*(year-1971) + (year - 1969)/4;
for(int i = 0; i < month -1;i++){// 加上日期年的月份天数
days += monthDay[i];
}
if( (year % 400 == 0 || year % 4 == 0 && year % 100 != 0) && month >2){
days += 1;// 如果 日期年 是闰年，且日期月份 大于 2月，所以它的天数要加1
}
days += day;// 再加上日期月份零碎的几天
return week[(days+3) % 7];
}
}
``````

# 代码二（这个就不讲了，跟上一个代码差不多）：

``````class Solution {
public String dayOfTheWeek(int day, int month, int year) {
String[] week = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
int[] monthDay = {31,28,31,30,31,30,31,31,30,31,30};
int days = 4;// 底线日期，对应星期四，下标也是 4
for(int i  = 1971; i < year; i++){// 计算 日期年份 与 底线年份的天数差
boolean leap = i%400 == 0 || (i % 4 == 0 && i % 100 !=0);// 润年为 true，平年为 false
days +=  leap ? 366 :365;// 闰年 366天，平年 365天
}
for(int i = 0;i < month-1;i++){
days += monthDay[i];
if(i == 2 && (year % 400 == 0 || year % 4 == 0 && year % 100 !=0)){
days += 1;// 如果给定年份year 为闰年，且经历过2月，需要加一天。
}
}
days += day;
return week[days % 7];
}
}
``````

THE END