- using System;
- namespace Leap_Year
- {
- internal class Program
- {
- private static void Main(string[] args)
- {
- Console.WriteLine(" 闰年判断 ");
- Console.WriteLine("************************");
- Console.WriteLine("请输入一个年份:");
- try
- {
- int year = int.Parse(Console.ReadLine());
- if (LeapYear(year))
- {
- Console.WriteLine("您输入的是一个闰年!");
- }
- else
- {
- Console.WriteLine("您输入的是一个非闰年!");
- }
- }
- catch
- {
- Console.WriteLine("您输入的不是一个正确的年份!");
- }
- Console.ReadKey();
- }
- public static bool LeapYear(int year) //定义一个方法来判断是否闰年
- {
- if (year % 4 == 0 || year % 400 == 0 && year % 100 != 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- }