您的位置:首页 > 其它

03.if 和 switch结合练习

2016-10-31 19:34 113 查看
  1. [code]namespace _04.练习01
  • {
  • class Program
  • {
  • static void Main(string[] args)
  •     {
  • //请用户输入年份,再输入月份,输出该月有多少天
  • Console.WriteLine("请输入年份:");
  • int year =Convert.ToInt32(Console.ReadLine());
  • Console.WriteLine("请输入月份:");
  • int month = Convert.ToInt32(Console.ReadLine());
  •     switch (month)
  •     {
  •         case 1:
  •         case 3:
  •         case 5:
  •         case 7:
  •         case 8:
  •         case 10:
  •         case 12:
  • Console.WriteLine("该月有31天!");
  • break;
  •         case 4:
  •         case 6:
  •         case 9:
  •         case 11:
  • Console.WriteLine("该月有30天!");
  • break;
  •         case 2:
  •         if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
  •         {
  • Console.WriteLine("该月有29天.");
  • }
  •         else
  •         {
  • Console.WriteLine("该月有28天.");
  • }
  • break;
  • }
  • Console.ReadKey();
  • }
  • }
  • }
  • [/code]


    来自为知笔记(Wiz)

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