zoukankan      html  css  js  c++  java
  • C#的第一个应用

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace ConsoleApplication2
    {
    class Program
    {
    static void Main(string[] args)
    {
    while (true)
    {
    {
    List<string> str = new List<string>();
    int year, month;
    #region 获取正确的年份
    while (true)
    {
    Console.WriteLine("请输入正确的年份(1900-2100):");
    year = int.Parse(Console.ReadLine());
    if (year < 1900 || year > 2100)
    Console.WriteLine("输入错误,请重新输入年份");
    else
    {
    while (true)
    {
    Console.WriteLine("请输入月份(1-12):");
    month = int.Parse(Console.ReadLine());
    if (month < 1 || month > 12)
    Console.WriteLine("输入错误,请输入正确的月份");
    else
    {
    break;
    }

    }
    break;
    }
    Console.ReadLine();
    Console.Clear();

    }
    #endregion
    #region 计算到那年年的天数
    int dayofyear, crossyear = 0;
    for (int i = 1900; i < year; i++)
    {
    if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0)
    dayofyear = 366;
    else
    dayofyear = 365;
    crossyear += dayofyear;

    }
    #endregion
    #region 到那月的天数
    int dayofmonth, crossmonth = 0;
    for (int i = 1; i < month; i++)
    {
    if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
    {
    if (i == 2)
    dayofmonth = 29;
    else if (i < 8 && i % 2 != 0 || i >= 8 && i % 2 == 0)
    dayofmonth = 31;
    else
    dayofmonth = 30;
    }
    else
    {
    if (i == 2)
    dayofmonth = 28;
    else if (i < 8 && i % 2 != 0 || i >= 8 && i % 2 == 0)
    dayofmonth = 31;
    else
    dayofmonth = 30;
    }
    crossmonth += dayofmonth;
    }
    #endregion
    #region 计算空格
    int week, space;
    week = (crossyear + crossmonth) % 7 + 1;
    space = week - 1;
    for (int i = 0; i < space; i++)
    str.Add("");
    #endregion
    #region 添加台历
    int day;
    if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
    {
    if (month == 2)
    day = 29;
    else if (month < 8 && month % 2 != 0 || month >= 8 && month % 2 == 0)
    day = 31;
    else
    day = 30;
    }
    else
    {
    if (month == 2)
    day = 28;
    else if ((month < 8 && month % 2 != 0) || (month >= 8 && month % 2 == 0))
    day = 31;
    else
    day = 30;
    }
    for (int i = 1; i <= day; i++)
    str.Add(i.ToString());
    #endregion
    #region 输出台历
    Console.WriteLine("******************************************************");
    Console.WriteLine("一 二 三 四 五 六 日");
    for (int i = 0; i < str.Count; i++)
    {
    if (i % 7 == 0 && i != 0)
    Console.WriteLine();

    Console.Write(str[i] + " ");
    }
    Console.WriteLine();
    Console.WriteLine("******************************************************");
    #endregion
    }
    Console.WriteLine("程序结束,请按确认键结束");
    Console.ReadLine();
    Console.Clear();

    }
    }
    }
    }

  • 相关阅读:
    IDEA使用
    虚拟机笔记 -- 基础
    虚拟机异常 -- 汇总
    虚拟机笔记 -- 设置静态IP
    虚拟机异常 -- 主机无法ping通虚拟机
    虚拟机笔记 -- 安装配置
    Git-分支命名规范
    SourceTree-Access denied问题解决
    Git初始化基本操作
    SpringBoot2 配置prometheus浏览器访问404
  • 原文地址:https://www.cnblogs.com/lxsir/p/6752479.html
Copyright © 2011-2022 走看看