Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Leap_Year
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Enter Year to Discover Leap Year:");
- var year = Console.ReadLine(); //get user input
- String newDateString = String.Format("05/01/{0}",year.ToString()); //format a complete date
- DateTime myDate;
- if (DateTime.TryParse(newDateString, out myDate)) //parse date from userinput
- {
- if (DateTime.IsLeapYear(myDate.Year))
- {
- Console.WriteLine(myDate.Year.ToString() + " is leapyear");
- }
- else
- {
- Console.WriteLine(myDate.Year.ToString() + " is not leapyear");
- }
- }
- else
- {
- Console.WriteLine("Invalid year input");
- }
- Console.ReadKey(); //pause the program
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement