它是说它必须返回一个字符串,但我看不出它有什么问题?我认为 numericDayOfWeek 应该可以正常工作?
public String getDayOfWeek(){
if(numericDayOfWeek==0){
return "Saturday";
}
if(numericDayOfWeek==1){
return "Sunday";
}
if(numericDayOfWeek==2){
return "Monday";
}
if(numericDayOfWeek==3){
return "Tuesday";
}
if(numericDayOfWeek==4){
return "Wednesday";
}
if(numericDayOfWeek==5){
return "Thursday";
}
if(numericDayOfWeek==6){
return "Friday";
}
}
这是完整的代码
public class DayOfWeek {
int myMonth, myDayOfMonth, myYear, myAdjustment, numericDayOfWeek;
public DayOfWeek(int month, int dayOfMonth, int year){
myMonth = month;
myDayOfMonth = dayOfMonth;
myYear = year;
}
public int getNumericDayOfWeek(){
if(myMonth==1){
myAdjustment = 1;
if(myYear%4==0){
myAdjustment-=1;
}
}
if(myMonth==2){
myAdjustment = 4;
if(myYear%4==0){
myAdjustment-=1;
}
}
if(myMonth==3){
myAdjustment = 4;
}
if(myMonth==4){
myAdjustment = 0;
}
if(myMonth==5){
myAdjustment = 2;
}
if(myMonth==6){
myAdjustment = 5;
}
if(myMonth==7){
myAdjustment = 0;
}
if(myMonth==8){
myAdjustment = 3;
}
if(myMonth==9){
myAdjustment = 6;
}
if(myMonth==10){
myAdjustment = 1;
}
if(myMonth==11){
myAdjustment = 4;
}
if(myMonth==12){
myAdjustment = 6;
}
int fourDivides = myYear / 4;
numericDayOfWeek = myAdjustment + myDayOfMonth + (myYear-1900) + fourDivides;
return numericDayOfWeek;
}
public String getDayOfWeek(){
if(numericDayOfWeek==0){
return "Saturday";
}
if(numericDayOfWeek==1){
return "Sunday";
}
if(numericDayOfWeek==2){
return "Monday";
}
if(numericDayOfWeek==3){
return "Tuesday";
}
if(numericDayOfWeek==4){
return "Wednesday";
}
if(numericDayOfWeek==5){
return "Thursday";
}
if(numericDayOfWeek==6){
return "Friday";
}
}
public int getMonth(){
}
public String getMonthString(){
}
public int getDayOfMonth(){
}
public int getYear(){
}
}