c#输入年份测试平年闰年

设计窗口:
在这里插入图片描述
输入一个年份,点击判断按钮时,判断平年还是闰年.
普通年:能被4整除但不能被100整除的年份为普通闰年。
世纪年:能被400整除的为世纪闰年。
平年就是除了闰年以外的年份都是平年。
代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _02测试平年闰年
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int year = int.Parse(textBox1.Text);
            int i = year % 4;
            int j = year % 400;
            if (i==0||j==0)
            {
                label2.Text = year.ToString() + "是闰年";
            }
            else
            {
                label2.Text = year.ToString() + "是平年";
            }
        }
    }
}

猜你喜欢

转载自blog.csdn.net/qq_43434300/article/details/85527347