Advertisement
lmarkov

LeapYear

Jan 29th, 2013
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 KB | None | 0 0
  1. /*
  2.  * Write a program that reads a year from the console and checks whether it is a leap. Use DateTime.
  3. */
  4.  
  5. using System;
  6.  
  7. class LeapYear
  8. {
  9.     static void Main()
  10.     {
  11.         int yearToCheck;
  12.         do{
  13.         Console.WriteLine("Enter year (1 to 9999): ");
  14.         }while(!(int.TryParse(Console.ReadLine(), out yearToCheck) && yearToCheck>=1 && yearToCheck<=9999));
  15.  
  16.         bool result = DateTime.IsLeapYear(yearToCheck);
  17.  
  18.         if (result == false)
  19.         {
  20.             Console.WriteLine("{0} is not leap!",yearToCheck);
  21.         }
  22.         else
  23.         {
  24.             Console.WriteLine("{0} is leap!",yearToCheck);
  25.         }
  26.  
  27.         Console.WriteLine();
  28.         Main();
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement