zoukankan      html  css  js  c++  java
  • 用户输入年,月,日,计算该日是该年的第几天?需要考虑2月份的问题

     1 class Program
     2     {
     3         static void Main(string[] args)
     4         {
     5             //用户输入年,月,日,计算该日是该年的第几天?需要考虑2月份的问题
     6             int year = 2015;
     7             int month = 5;
     8             int day = 8;
     9 
    10             //计算是哪年 哪月 哪日
    11             //1,3,5,7,8,10,12是31
    12             //闰年29天,平年28天
    13             //4,6,9,11是30天
    14             //占时认为2月份是28天
    15 
    16             //储存每个月的天数,查表法
    17             int[] data = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    18 
    19             //3月5日:第0个月+第一个月+5天
    20             //2月5日:31+5
    21 
    22             int days = 0;
    23             for (int i = 0; i < month-1; i++)
    24             {
    25                 days += data[i];
    26             }
    27             days += day;
    28             if (month > 2)//如果月份大于2,则看是否需要补一天
    29             {
    30                 //判断是否是闰年,能被 4 整除 但是不能被100整除 或者能被四百整除
    31                 if (IsRun(year))
    32                 {
    33                     days++;//如果是闰年,加一天
    34                 }
    35             }
    36             Console.WriteLine(days);
    37             
    38             Console.ReadKey();
    39         }
    40 
    41         //判断闰年的方法
    42         static bool IsRun(int year)
    43         {
    44             if((year%4==0 && year%100!=0)||year%400==0)
    45             {
    46                 return true;
    47             }
    48             else
    49             {
    50                 return false;
    51             }
    52         }
    53     }
  • 相关阅读:
    Android listview 的应用
    Android 创建自定义布局
    Android Dialog
    android ProgressBar
    Lilac Pwn stack4-stack_pivoting Writeup
    CTFHUB Pwn ret2shellcode Writeup
    Lilac Pwn stack3-rop Writeup
    函数调用过程与栈帧结构
    线性回归及Python实现
    Google Kick Start Round A 2020
  • 原文地址:https://www.cnblogs.com/pengyouqiang88/p/5022132.html
Copyright © 2011-2022 走看看