黑色星期五&星期几
上一篇 /
下一篇 2012-05-30 23:36:04
/ 个人分类:TestNG/Ant/Eclipse/Java
public void blackfriday() {
int d=13;
System.out.println("pls input year(4 single number):");
int y = new Scanner(System.in).nextInt();
for(int m=1;m<13;++m){
if(friday(y,m,d)==1)
System.out.println("blackFriday: "+m+"月"+d+"日");
}
}
int friday(int y,int m,int d){
int c=y/100;
y=y-100*c;
int w;
if(m<3){
m+=12;
y-=1;
}
w=c/4-2*c+y+y/4+13*(m+1)/5+d-1;
if(w<0) w+=7;
w%=7;
if(w==5)
return 1;
else return 0;
}
}
星期几:
public void weekDay() {
int w = 0;
String week[]= {"Sunday:星期日","Monday:星期一","Tuesday:星期二","Wednesday:星期三","Thursday:星期四","Friday:星期五","Saturday:星期六"};
//System.out.println("pls input year(4 single number):");
int y = new Scanner(System.in).nextInt();
//System.out.println("pls input month:");
int m = new Scanner(System.in).nextInt();
//System.out.println("pls input day:");
int d = new Scanner(System.in).nextInt();
int c=y/100;
y=y-100*c;
if(m<3){
m+=12;
y-=1;
}
w=c/4-2*c+y+y/4+13*(m+1)/5+d-1;
if(w<0) w+=7;
w%=7; //求余
System.out.println(week[w]);
}
}
收藏
举报
TAG: