//根据输入的年月日,确定这一天是星期几
final int year = 1900;
int sum;
Scanner input = new Scanner(System.in);
System.out.print("请输入年份:");
int years = input.nextInt();
System.out.print("请输入月份:");
int months = input.nextInt();
System.out.print("请输入日:");
int days = input.nextInt();
if (years>year) {
if (years % 4 == 0 && years % 100 != 0 || years % 400 == 0) {
sum = (years-year)*365+(years-year)/4-1+days;
} else {
sum = (years-year)*365+(years-year)/4+days;
}
for (int i = 1,j; i < months; i++) {
j=31;
switch (i){ case 4: case 6: case 9: case 11:
j=30;
break;
case 2:
j= year%4==0?29:28;
break;
}
sum +=j;
}
switch (sum % 7 ){
case 0:
System.out.println(years+"年"+months+"月"+days+"日"+"是星期天");
break;
case 1:
System.out.println(years+"年"+months+"月"+days+"日"+"是星期一");
break;
case 2:
System.out.println(years+"年"+months+"月"+days+"日"+"是星期二");
break;
case 3:
System.out.println(years+"年"+months+"月"+days+"日"+"是星期三");
break;
case 4:
System.out.println(years+"年"+months+"月"+days+"日"+"是星期四");
break;
case 5:
System.out.println(years+"年"+months+"月"+days+"日"+"是星期五");
break;
case 6:
System.out.println(years+"年"+months+"月"+days+"日"+"是星期六");
break;
}
}else {
System.out.println("您输入的年份不对");
}
实验结果