Morning sun teacher told how to judge the leap year;
//judgment is not a leap year, the normal years, is a multiple of 4 but not a multiple of 100;
//Century year is a multiple of 400
//Enter a year to determine if it is leap years
//console.write ("Please enter a year:");
int year = Int. Parse (Console.ReadLine ());
if (year>0&&year<=9999)
{
if (year%4==0&&year%100!=0| | year%400==0)
{
Console.WriteLine ("The number of years you enter is a leap year! ");
}
Else
{
Console.WriteLine ("The Year you entered is common year!") ");
}
}
Console.ReadLine ();
Switch case
The switch case must be used in conjunction with break, which is a jump statement, which jumps out of the nearest {} When using the switch case;
switch (the value variable name of the data type)
Case:
Enter the month, the number, the output is the first day of this year? With switch case
Each year the 1,3,5,7,8,10,12 month is 31 days;
The February of 2016 is 29 days;
The other 4,6,9,11 are 30 days;
Code:
int m1 = to, M2 =, M3 = To, M4 =, M5 = To, M6 =, M7 = to, M8 = to, M9 = 31, M10 =, M11 =: M12
Console.Write ("Please enter the month:");
int m = Int. Parse (Console.ReadLine ());
Console.Write ("Please enter the date:");
int d = Int. Parse (Console.ReadLine ());
if (M > 0 && m <= 12)
{
if (d > 0 && d <= 31)
{
Console.ReadLine ();
}
Else
{
Console.WriteLine ("You entered the wrong!! ");
}
}
Else
{
Console.WriteLine ("Your input is wrong!") ");
}
Switch (m)
{
Case 1:
Console.WriteLine ("First" + D + "Day");
Break
Case 2:
Console.WriteLine ("First" + (M1 + D) + "Day");
Break
Case 3:
Console.WriteLine ("First" + (M1 + m2 + D) + "Day");
Break
Case 4:
Console.WriteLine ("First" + (M1 + m2 + m3 + d) + "Day");
Break
Case 5:
Console.WriteLine ("First" + (M1 + m2 + m3 + m4 + D) + "Day");
Break
Case 6:
Console.WriteLine ("First" + (M1 + m2 + m3 + M4 + M5 + D) + "Day");
Break
Case 7:
Console.WriteLine ("First" + (M1 + m2 + m3 + M4 + M5 + M6 + D) + "Day");
Break
Case 8:
Console.WriteLine ("First" + (M1 + m2 + m3 + M4 + M5 + M6 + M7 + D) + "Day");
Break
Case 9:
Console.WriteLine ("First" + (M1 + m2 + m3 + M4 + M5 + M6 + M7 + m8 + D) + "Day");
Break
Case 10:
Console.WriteLine ("First" + (M1 + m2 + m3 + M4 + M5 + M6 + M7 + m8 + M9 + D) + "Day");
Break
Case 11:
Console.WriteLine ("First" + (M1 + m2 + m3 + M4 + M5 + M6 + M7 + m8 + M9 + M10 + D) + "Day");
Break
Case 12:
Console.WriteLine ("First" + (M1 + m2 + m3 + M4 + M5 + M6 + M7 + m8 + M9 + M10 + M11 + D) + "Day");
Break
Default
Console.WriteLine ("Your input is wrong!") ");
Break
}
Console.ReadLine ();
Insert Picture
Use the leap year that you have just mentioned to do a case:
Enter month and date to see if the format is correct
Code:
Enter month and date to see if the format is correct
Each year the 1,3,5,7,8,10,12 month is 31 days;
The February of 2016 is 29 days;
The other 4,6,9,11 are 30 days;
Console.Write ("Please enter the Year:");
int year = Int. Parse (Console.ReadLine ());
if (Year > 0 && Year <= 9999)
{
Console.Write ("Please enter the month:");
int m = Int. Parse (Console.ReadLine ());
if (M > 0 && m <= 12)
{
Console.Write ("Please enter the date:");
int d = Int. Parse (Console.ReadLine ());
if (m = = 1 | | m = = 3 | | m = = 5 | | m = = 7 | | m = = 8 | | m = = | | m = = 12)
{
if (d > 0 && d <= 31)
{
Console.WriteLine (Year + "years" + M + "month" + D + "Day");
}
Else
{
Console.WriteLine ("The number you entered is wrong!");
}
}
else if (m = = 4 | | m = = 6 | | m = = 9 | | m = = 11)
{
if (d > 0 && d <= 30)
{
Console.WriteLine (Year + "years" + M + "month" + D + "Day");
}
Else
{
Console.WriteLine ("The number you entered is wrong!");
}
}
else//m==2
{
if (year% 4 = = 0 && year%!! = 0 | | year% 400 = = 0)
{
if (d > 0 && d <= 29)
{
Console.WriteLine (Year + "years" + M + "month" + D + "Day");
}
Else
{
Console.WriteLine ("The number you entered is wrong!") ");
}
}
Else
{
if (d > 0 && d <= 28)
{
Console.WriteLine (Year + "years" + M + "month" + D + "Day");
}
Else
{
Console.WriteLine ("The number you entered is wrong!") ");
}
}
}
}
Else
{
Console.WriteLine ("The Month you entered is incorrect!) ");
}
}
Else
{
Console.WriteLine ("You entered the wrong year!") ");
}
Insert
Today feel a little bit of introduction to the meaning, write code to better than yesterday, yesterday is able to understand but his problem is not too smooth, do not know how to write, but the teacher said it is time to understand, their own writing can not, practice a day today feel more comfortable, good phenomenon is not? The above case at the same table Mr. Chen with switch cases to do, did the first day of the problem after the switch case, dare not compliment or if else handy, think Mr. Chen's brain is very flexible, there is a problem in the morning we use if he used the condition of the operation is simple and time-saving ... It's great to have such a small partner.
3.8 accompanying notes finishing