Switch Case statement

Source: Internet
Author: User
Tags case statement switch case

Switch Case Statement

Enter a year and a month, judging is the day of the first day?

Console.WriteLine ("Please enter the Year:");

int year = Int. Parse (Console.ReadLine ());

Console.WriteLine ("Please enter the month:");

int month = Int. Parse (Console.ReadLine ());

Console.WriteLine ("Please enter the day:");

int day = Int. Parse (Console.ReadLine ());

int sum=0;

If ((year% 400 = = 0) | | (Year% + = 0) && (year% 4 = = 0)))

{

Switch (month)

{

Case 1:

Sum =day;

Break

Case 2:

Sum =day + 31;

Break

Case 3:

Sum =day + 31 + 29;

Break

Case 4:

Sum =day + 31 + 29 + 31;

Break

Case 5:

Sum =day + 31 + 29 + 31 + 30;

Break

Case 6:

Sum =day + 31 + 29 + 31 + 30 + 31;

Break

Case 7:

Sum =day + 31 + 29 + 31 + 30 + 31 + 30;

Break

Case 8:

Sum =day + 31 + 29 + 31 + 30 + 31 + 30 + 31;

Break

Case 9:

Sum =day + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31;

Break

Case 10:

Sum =day + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30;

Break

Case 11:

Sum =day + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31;

Break

Case 12:

Sum =day + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30;

Break

Default

Console.WriteLine ("Input Error");

Break

}

}

Else

{

Switch (month)

{

Case 1:

Sum =day;

Break

Case 2:

Sum =day + 31;

Break

Case 3:

sum = day + 31 + 28;

Break

Case 4:

Sum =day + 31 + 28 + 31;

Break

Case 5:

Sum =day + 31 + 28 + 31 + 30;

Break

Case 6:

Sum =day + 31 + 28 + 31 + 30 + 31;

Break

Case 7:

Sum =day + 31 + 28 + 31 + 30 + 31 + 30;

Break

Case 8:

Sum =day + 31 + 28 + 31 + 30 + 31 + 30 + 31;

Break

Case 9:

Sum =day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31;

Break

Case 10:

Sum =day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30;

Break

Case 11:

Sum =day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31;

Break

Case 12:

Sum =day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30;

Break

Default

Console.WriteLine ("Input Error");

Break

}

}

Console.WriteLine ("This is {1} days of {0} years", year,sum);

Switch Case statement

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.