SELECT statement----Switch case

Source: Internet
Author: User
Tags switch case

The switch case where you learned the choice statement today is a multi-select scenario that you can use.

Case:

Enter the month and the number of the output is how many days this year
The 1,3,5,7,8,10,12 month is 31 days a year.
This year's February is 28 days the other is 30

            intM1 = to, M2 = -, M3 = to, M4 = -, M5 = to, M6 = -, M7 = to, M8 = to, M9 = -, M10 = to, M11 = -;            ----don't need to define the volume for December, because Console.Write ("Please enter the month:"); intm =int.            Parse (Console.ReadLine ()); Console.Write ("Please enter the date:"); intD =int.            Parse (Console.ReadLine ()); Switch(m)-------Once there is a match, one of them is executed, the others are not executed, and no match goes to default. Break means to jump out of a selection.             {                 Case 1: Console.WriteLine ("today is the first of the year"+ D +"days. ");  Break;  Case 2: Console.WriteLine ("today is the first of the year"+ (M1 + D) +"days. ");  Break;  Case 3: Console.WriteLine ("today is the first of the year"+ (M1 + m2 + d) +"days. ");  Break;  Case 4: Console.WriteLine ("today is the first of the year"+ (m1 + m2 + m3 + d) +"days. ");  Break;  Case 5: Console.WriteLine ("today is the first of the year"+ (m1 + m2 + m3 + m4 + D) +"days. ");  Break;  Case 6: Console.WriteLine ("today is the first of the year"+ (m1 + m2 + m3 + M4 + M5 + D) +"days. ");  Break;  Case 7: Console.WriteLine ("today is the first of the year"+ (m1 + m2 + m3 + M4 + M5 + M6 + D) +"days. ");  Break;  Case 8: Console.WriteLine ("today is the first of the year"+ (m1 + m2 + m3 + M4 + M5 + M6 + M7 + D) +"days. ");  Break;  Case 9: Console.WriteLine ("today is the first of the year"+ (m1 + m2 + m3 + M4 + M5 + M6 + M7 + m8 + D) +"days. ");  Break;  Case Ten: Console.WriteLine ("today is the first of the year"+ (m1 + m2 + m3 + M4 + M5 + M6 + M7 + m8 + M9 + D) +"days. ");  Break;  Case  One: Console.WriteLine ("today is the first of the year"+ (m1 + m2 + m3 + M4 + M5 + M6 + M7 + m8 + M9 + M10 + D) +"days. ");  Break;  Case  A: Console.WriteLine ("today is the first of the year"+ (m1 + m2 + m3 + M4 + M5 + M6 + M7 + m8 + M9 + M10 + M11 + D) +"days. ");  Break; default: Console.WriteLine ("your input is incorrect. ");  Break; }

Case: (Thought for a long time, this question.) )

Enter a year, month, and day. See if the format is correct.

Console.Write ("Please enter a year:"); intYear =int.            Parse (Console.ReadLine ()); if(Year <=9999&& year >0) {Console.Write ("Please enter a month:"); intm =int.                Parse (Console.ReadLine ()); if(M <= A&& m >=1) {Console.Write ("Please enter a date:"); intD =int. Parse (Console.ReadLine ());                    --------from here to up very simple, to the following choice statement card. if(M = =1|| m = =3|| m = =5|| m = =7|| m = =8|| m = =Ten|| m = = A-------began to be written here (D<=31&&d>=1) later reacted to the wrong, haha {if(d >=1&& D <= to) {Console.WriteLine ("input format is correct"); }                        Else{Console.WriteLine ("you have entered an incorrect format. "); }                    }                    Else if(M = =4|| m = =6|| m = =9|| m = = One)                    {                        if(d >=1&& D <= -) {Console.WriteLine ("input format is correct"); }                        Else{Console.WriteLine ("you have entered an incorrect format. "); }                    }                    Else                    {                        if(Year%4==0&& Year% -!=0) || (Year% -==0))//judge leap years, know the law of Leap year is good to write, four A leap, a century does not leap, 400 years again leap. {The year is a full hundred, it must be a multiple of 400 is a leap years; not 40.                            A multiple of 0 years, even a multiple of 4 is not a leap year. if(d >=1&& D <= in) {Console.WriteLine ("input format is correct"); }                            Else{Console.WriteLine ("you have entered an incorrect format. "); }                        }                        Else                        {                            if(d >=1&& D <= -) {Console.WriteLine ("input format is correct"); }                            Else{Console.WriteLine ("you have entered an incorrect format. "); }                        }                    }                }                Else//Month not 1~12{Console.WriteLine ("you have entered an incorrect format. "); }            }            Else//not 9999~0 .{Console.WriteLine ("you have entered an incorrect format. "); }

SELECT statement----Switch case

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.