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