从1990年1月1日开始,三天打鱼两天晒网,
问某年某月某日是打鱼还是晒网
1 2 3 打鱼 4 5 晒网
6 7 8 打鱼 9 10 晒网
余数 1 2 3 打鱼
4 0 晒网
获取总天数 % 5 根据余数判断
总年数 + 总月数 + 对应日期 == 总天数
2021.10.8
1990 - 2020整年
1~9天
8+8
public class ArrayExer6 {
public static void main(String[] args) {
//输入年月日
Scanner scan = new Scanner(System.in);
System.out.println("输入年");
int year = scan.nextInt();
System.out.println("输入月");
int month = scan.nextInt();
System.out.println("输入日");
int day = scan.nextInt();
//定义变量 记录总天数
int days = 0;
//整年的天数
for (int i = 1990; i < year; i++) {
if (i%400==0||i%4==0&&i%100!=0){
days+=366;
}else {
days+=355;
}
}
//整月的天数
for (int i = 1; i < month; i++) {
switch (i){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days+=31;
break;
case 4:
case 6:
case 9:
case 11:
days+=30;
break;
case 2:
if (i%400==0||i%4==0&&i%100!=0){
days+=29;
}else {
days+=28;
}
break;
}
}
//指定日期
days+=day;
//%5根据余数进行判断即可
if (days %5==0||days%5==4){
System.out.println("晒网");
}else {
System.out.println("打鱼");
}
}
}