您的位置:首页 > 职场人生

黑马程序员之C#学习笔记: 判断该月份有几天

2012-11-14 20:54 483 查看
---------------------------------------------------
2345王牌技术员联盟、2345王牌技术员联盟、期待与您交流!---------------------------------------------------------

用户输入年份和月份 判断该月份有几天 该练习主要是练习同学们要掌握的知识点有:一:掌握闰年的判断 二:学会使用if多分枝条件判断结构 三: switch选择器的使用 那么该小程序的具体实现如下:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Test6

{

calss Program

{

static void Main(string[] args)

{

Console.WriteLine("请输入一个年份:");

int Year = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("请输入一个月份:");

int Month = Convert.ToInt32(Console.ReadLine());

if ((Year % 400 == 0) || ((Year % 4 == 0) && (Year % 100 != 0)))

{

switch (Month)

{

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

Console.WriteLine("该月有31天");

break;

case 2:

Console.WriteLine("该月有29天");

break;

default:

Console.WriteLine("该月有30天");

break;

}

}

else

{

switch (Month)

{

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

Console.WriteLine("该月有31天");

break;

case 2:

Console.WriteLine("该月有28天");

break;

default:

Console.WriteLine("该月有30天");

break;

}

}

Console.ReadKey();

}

}

}

---------------------------------------------------
2345王牌技术员联盟、2345王牌技术员联盟、期待与您交流!---------------------------------------------------------

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐