• Java三天大鱼两天晒网


     1 package Demo;
     2 import java.util.Scanner;
     3 public class Demo01 {
     4     /*中国有句俗语叫“三天打鱼两天晒网”。某人从2019年1月1日起开始“三天打鱼两天晒网”问这个人在以后的某一天中是“打鱼"还是“晒网*/
     5     public static void main(String[] args){
     6         Scanner sc = new Scanner(System.in);//建立扫描器
     7         System.out.println("请输入年-月-日:");
     8         int year = sc.nextInt();
     9         int month = sc.nextInt();
    10         int day = sc.nextInt();
    11         if (year>=2019){
    12             int jg = days(year,month,day);
    13             System.out.println("第"+jg+"天");
    14             if (jg % 5 == 1 || jg % 5 == 2 || jg % 5 ==3){
    15                 System.out.println("打鱼");
    16             }
    17             else{
    18                 System.out.println("晒网");
    19             }
    20         }
    21 
    22         //System.out.println("您输入的"+year+"年"+month+"月"+day+"日");
    23     }
    24     public static int days(int year,int month,int day){
    25         int[] Month= {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    26         //计算2019-1-1的总天数
    27         int sum = 0;
    28         for (int i = 2019; i < year; i++)
    29         {
    30             if (i % 4 == 0 && i % 100 !=0 || i % 400 == 0)//判断是否闰年
    31             {
    32                 Month[1] = 29;
    33             }
    34             //计算该年有多少天 循环月
    35             for(int j = 0; j <= 11; j++)
    36             {
    37                 sum+=Month[j];
    38             }
    39         }
    40         //循环月
    41         for (int i = 0; i < month-1; i++)
    42         {
    43             sum+=Month[i];
    44         }
    45         return sum+day;
    46     }
    47 }
  • 相关阅读:
    jQuery序列化
    jQuery的ajax与django传参
    Django中的cookie与session操作
    Django文件上传
    Django表单的简单应用
    django加载模板文件
    django-admin.py创建项目失败解决方法
    django笔记
    unity创建xml与加载xml
    JavaScript相关
  • 原文地址:https://www.cnblogs.com/bingquan1/p/12454426.html
Copyright © 2020-2023  润新知