本帖最后由 孙茜茜 于 2013-5-20 08:27 编辑
才学了一天视频,写这段思路基本靠当年学c的遗留记忆
s2+=monthday; 这句提示找不到monthday符号
class Fri13
{
void main(String[] args)
{
int year=1900,month=1,s1;
int[] result={0,0,0,0,0,0,0};
int week,i,k;
for (;year<2300;year+=1)
{ if (year%4==0)
{int[] monthday={0,31,28,31,30,31,30,31,31,30,31,30,31};}
else {int[] monthday={0,31,29,31,30,31,30,31,31,30,31,30,31};}
for (;month<13;month+=1)
{int s2=0;
s1=365*(year-1900)-(year/4-1);
for (i=0;i<month-1;i+=1)
{
s2+=monthday;
}
week=(s1+s2)%7;
result[week-1]+=1;
}
}
System.out.println(result[0]+","+result[1]+","+result[2]+","+result[3]+","+result[4]+","+result[5]+","+result[6]);
}
} |