给大家分享一个简单的小万年历,输入年份,输入月份,输出这个月的第一天是星期几!
import java.util.Scanner;
public class L {
public static void main(String[] args) {
Scanner a = new Scanner(System.in);
System.out.println("请输入年份:");
int y = a.nextInt();
System.out.println("请输入月份:");
int m = a.nextInt();
int total=0;
for(int i= 1900; i<y;i++)
{
if(i%4 == 0 && i%100 != 0||i%400 == 0)
{
total+=366;
}
else
{
total+=365;
}
}
for(int i=1;i<m;i++ )
{
int md = 31;
switch(i)
{
case 4:
case 6:
case 9:
case 11:
md = 30;
break;
case 2:
if(y%4 == 0 && y%100 != 0||y%400 == 0){
md=29;
}
else{
md=28;
}
}
total+=md;
}
total++;
System.out.println(total%7);
}
}
|
|