Switch Structure 2016/03/08

Source: Internet
Author: User

Switch 03/08

First, the structure

Switch () {case *:; Break;......default:; Brek;}

Exercise: Enter a date to determine the day of the year?

Console.Write ("Please enter the month");
int m = Int. Parse (Console.ReadLine ());
Console.Write ("Please enter the date");
int d = Int. Parse (Console.ReadLine ());
int m1 = to, M2 = 30, M3 = to, M4 =, M5 = To, M6 =--M7 =--M8 = =, M9 =-M10
Switch (m)
{
Case 1:
Console.WriteLine ("S" + (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 ("You entered the wrong!") ");
Break
}

Second, the judgement leap year, the ordinary years, is a multiple of 4 but not a multiple of 100; the World Memorial is a multiple of 400 (year%4==0&&year%100!=0) | | Year%100==0
Console.Write ("Please enter the Year:");
int year = Int. Parse (Console.ReadLine ());
if (year >= 0 && year <= 9999)
{
If ((year% 4 = = 0 && year%! = 0) | | year% 100 = = 0)
{
Console.WriteLine ("You are entering a leap year. ");
}
Else
{
Console.WriteLine ("You entered the common year. ");
}
}
Else
{
Console.WriteLine ("You entered the wrong year!") ");
}

Enter a year between any 0--9999, enter the correct date correctly, and finally output the date correctly, otherwise the input format is incorrect.

Console.Write ("Please enter the Year:");
int y = Int. Parse (Console.ReadLine ());
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 (y >= 0 && y <= 9999)
{

if (M >= 1 && m <= 12)
{
if (m = = 1 | | m = = 3 | | m = = 5 | | m = = 7 | | m = = 8 | | m = = | | m = = 12)
{

if (d >= 1 && d <= 31)
{
Console.Write ("You entered is" + y + "year" + M + "month" + D + "number");
}
Else
{
Console.WriteLine ("The number of formats you entered is incorrect.) ");
}
}
else if (m = = 4 | | m = = 6 | | m = = 9 | | m = = 11)
{

if (d >= 1 && d <= 30)
{
Console.Write ("You entered is" + y + "year" + M + "month" + D + "number");
}
Else
{
Console.WriteLine ("The number of formats you entered is incorrect.) ");
}
}
else//m==2
{
if (y% 4 = = 0 && y% = 0) | | y% 100 = 0)
{

if (d >= 1 && d <= 29)
{
Console.Write ("You entered is" + y + "year" + M + "month" + D + "number");
}
Else
{
Console.WriteLine ("The number of formats you entered is incorrect.) ");
}
}
Else
{

if (d >= 1 && d <= 28)
{
Console.Write ("You entered is" + y + "year" + M + "month" + D + "number");
}
Else
{
Console.WriteLine ("The number of formats you entered is incorrect.) ");
}
}
}
}
Else
{
Console.WriteLine ("The Month format you entered is wrong. ");
}
}
Else
{
Console.WriteLine ("You have entered a wrong year format. ");
}

Switch Structure 2016/03/08

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.