- 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;
- }
- }
- }
- }