返回顶部

一缕半夏微光

温柔半两,从容一生

导航

编写一个控制台应用程序,可根据输入的月份判断所在季节(C#)

一、效果如下:

二、代码如下:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace Test2
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             int i;
14             Console.WriteLine("-----通过月份判断所在季节-----");
15             while (true)
16             {
17                 Console.WriteLine("****************************菜单****************************");
18                 Console.WriteLine("******1.1月    2.2月    3.3月   4.4月    5.5月    6.6月*****");
19                 Console.WriteLine("****7.7月    8.8月    9.9月   10.10月  11.11月  12.12月*****");
20                 Console.WriteLine("**************************13.退出***************************");
21                 Console.WriteLine("请输入月份序号:");
22                 i = int.Parse(Console.ReadLine());
23                 switch (i)
24                 {
25                     case 3:
26                     case 4:
27                     case 5:
28                         Console.WriteLine("春季");
29                         break;
30                     case 6:
31                     case 7:
32                     case 8:
33                         Console.WriteLine("夏季");
34                         break;
35                     case 9:
36                     case 10:
37                     case 11:
38                         Console.WriteLine("秋季");
39                         break;
40                     case 12:
41                     case 1:
42                     case 2:
43                         Console.WriteLine("冬季");
44                         break;
45                     case 13:
46                         Console.WriteLine("退出成功");
47                         break;
48                     default: 
49                         Console.WriteLine("输入错误!"); 
50                         break;
51                 }//switch结束
52                 if (i == 13) 
53                     break; //退出系统
54             }//while结束
55         }
56     }
57 }

参考链接:https://blog.csdn.net/lady_killer9/article/details/78207266?utm_source=blogxgwz5

posted on 2021-10-12 21:40  一缕半夏微光  阅读(325)  评论(0编辑  收藏  举报