Use the DateTime class to judge the problem of leap year

Source: Internet
Author: User

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceleap year Exercise {classProgram {Static voidMain (string[] args) {            //1, enter the month and day, see whether the date entered is correct//2. Whether the output is a leap year (29 days), the output date//Leap Year is judged by 4 and cannot be divisible by 100 for leap years//century can be divisible by 400 is a leap year//3, the output is the first day of this year//Prompt user to enter dateDateTime dt =NewDateTime (); intA = dt. year;//the variable that defines the year is a            intb = dt. Month;//the variable that defines the month is B            intc = dt. Day;//the variable that defines the day is CConsole.Write ("Please enter the date:"); Try//exception statement processing, to determine whether the user input is correct, if the following content is executed correctly            {                strings =Console.ReadLine (); DT=DateTime.Parse (s); S= dt. ToString ("yyyy mm month DD Day"); if(A%4==0&& A% -!=0) || A -==0) {Console.WriteLine ("This is a leap year! "); }                Else{Console.WriteLine ("This is not a leap year! "); }                stringx = dt. Dayofweek.tostring ();//convert English week to Chinese                Switch(x) { Case "Monday": x ="Monday"; Break;  Case "Tuesday": x ="Tuesday"; Break;  Case "Wednesday": x ="Wednesday"; Break;  Case "Thursday": x ="Thursday"; Break;  Case "Friday": x ="Friday"; Break;  Case "Saturday": x ="Saturday"; Break;  Case "Sunday": x ="Week seven"; Break; } Console.WriteLine ("the date you entered is"+ A +"year of the first"+ (dt. DayOfYear) +"Oh, God!"+"\ t"+x); }            Catch//User Input Error{Console.WriteLine ("Sorry, the date you entered is incorrect! ");        } console.readline (); }    }}

Use the DateTime class to judge the problem of leap year

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.