【发布时间】:2014-12-01 02:04:18
【问题描述】:
我在下面有这段代码,它一直告诉我 Thanksgiving() 必须返回一个 int 类型的结果。我已经确定了所有结果以确保,但似乎没有任何效果!为什么我会收到此错误?
public class Thanksgiving
{
private static final int YEAR = 2000; // first valid year for this method
private static final int NOV1 = 3; // 2000/11/01 falls on a Wednesday
private static final int THURS = 4; // (Sun = 0, Mon = 1, ..., Sat = 6)
// Precondition: year > 1999
public static int thanksgiving(int year)
{
int day = firstOfMonth( year );
if ( day == THURS )
{
return (int) 22;
}
if ( day > THURS )
{
return (int) 29 - ( day - THURS );
}
if ( day < THURS )
{
return (int) 22 + ( THURS + day );
}
}
public static int firstOfMonth(int year)
{
int raw = year - 2000;
int day = NOV1;
for(int i = 0; i < raw; i++ )
{
if( i % 4 == 0 )
{
day = day + 2;
}
else
{
day++;
}
}
return day % 7;
}
public static void main(String[] args)
{
for(int year = 2000; year <= 2100; year++)
{
System.out.print("T'giving " + year + " is Nov " + thanksgiving(year) + "; ");
if (year % 3 == 1)
{
System.out.println();
}
}
}
}
【问题讨论】:
标签: java compiler-errors