C#入门篇5

编程入门 行业动态 更新时间:2024-10-13 14:22:34

C#<a href=https://www.elefans.com/category/jswz/34/1760670.html style=入门篇5"/>

C#入门篇5

#region switch语句public class C2{//使用switch语句如何使用public static void Fun2(){//显示提示Console.WriteLine("三种选择型号: 1=(小杯, ¥3.0) 2=(中杯, ¥4.0) 3=(大杯, ¥5.0)");Console.Write("您的选择是: ");//读入用户选择//把用户的选择赋值给变量nstring s = Console.ReadLine();int n = int.Parse(s);//根据用户的输入提示付费信息switch (n){case 1:Console.WriteLine("小杯,请付费¥3.0。");break;case 2:Console.WriteLine("中杯,请付费¥4.0。");break;case 3:Console.WriteLine("大杯,请付费¥5.0。");break;//缺省为中杯default:Console.WriteLine("中杯,请付费¥4.0。");break;}//显示结束使用提示Console.WriteLine("谢谢使用,欢迎再次光临!");}//一年中的第几天public static void Fun1(){//一年中的第几天Console.WriteLine("请输入年:");int inta = int.Parse(Console.ReadLine().Trim());//年
Console.WriteLine("请输入月:");int intb = int.Parse(Console.ReadLine().Trim());//月
Console.WriteLine("请输入日:");int intc = int.Parse(Console.ReadLine().Trim());//日int intd = 0;//表示第几天switch (intb){case 1:intd = intc + 0;break;case 2:intd = intc + 31;break;case 3:intd = intc + 31 + 28;break;case 4:intd = intc + 31 + 28 + 31;break;case 5:intd = intc + 31 + 28 + 31 + 30;break;case 6:intd = intc + 31 + 28 + 31 + 30 + 31;break;case 7:intd = intc + 31 + 28 + 31 + 30 + 31 + 30;break;case 8:intd = intc + 31 + 28 + 31 + 30 + 31 + 30 + 31;break;case 9:intd = intc + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31;break;case 10:intd = intc + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30;break;case 11:intd = intc + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31;break;case 12:intd = intc + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30;break;default:break;}//闰年的情况if (inta % 4 == 0 && inta % 100 != 0 || inta % 400 == 0){intd = intd + 1;Console.WriteLine("这是今年的第" + intd + "天!");}else{Console.WriteLine("这是今年的第" + intd + "天!");}}}//switch结合枚举的使用public class C2_1{enum Season{Spring = 1,Summer = 2,Fall = 3,Winter = 4}public static void Fun1(){lab:Console.WriteLine("请输入月份:");int intSeason = int.Parse(Console.ReadLine().Trim());switch (intSeason){case 11:case 12:case 1:Console.WriteLine("冬寒抱冰");break;case 2:case 4:Console.WriteLine("春意盎然");break;case 3:Console.WriteLine("春暖花开");break;case 5:case 6:case 7:Console.WriteLine("夏日炎炎");break;case 8:case 9:case 10:Console.WriteLine("秋风瑟瑟");break;default:Console.WriteLine("您输入的有误!");break;}goto lab;}public static void Fun2(){lab:Console.WriteLine("请输入月份:");int Sea = int.Parse(Console.ReadLine().Trim());int N = int.MinValue;if (Sea == 2 || Sea == 3 || Sea == 4){N = 1;}else if (Sea == 5 || Sea == 6 || Sea == 7){N = 2;}else if (Sea == 8 || Sea == 9 || Sea == 10){N = 3;}else if (Sea == 11 || Sea == 12 || Sea == 1){N = 4;}switch (N){case (int)Season.Spring:Console.WriteLine("春意盎然");break;case (int)Season.Summer:Console.WriteLine("夏日炎炎");break;case (int)Season.Fall:Console.WriteLine("秋色迷人");break;case (int)Season.Winter:Console.WriteLine("天寒地冻");break;}goto lab;}}//猜拳游戏public class GuessBox{enum GuessBoxing{Stone,Sword,Cloth}public static void Fun(){string str = Console.ReadLine();int num = int.MinValue;if (str == "石头"){num = 0;}else if (str == "剪刀"){num = 1;}else{num = 2;}//电脑出拳Random rm = new Random();int com = rm.Next(3);switch (num){case (int)GuessBoxing.Stone:if (com == 0){Console.WriteLine("电脑出石头,你出石头,平手");}else if (com == 1){Console.WriteLine("电脑出剪刀,你出石头,你赢了");}else if (com == 2){Console.WriteLine("电脑出布,你出石头,你输了");}break;case (int)GuessBoxing.Sword:if (com == 0){Console.WriteLine("电脑出石头,你出剪刀,你输了");}else if (com == 1){Console.WriteLine("电脑出剪刀,你出剪刀,平手");}else if (com == 2){Console.WriteLine("电脑出布,你出剪刀,你赢了");}break;case (int)GuessBoxing.Cloth:if (com == 0){Console.WriteLine("电脑出石头,你出布,你赢了");}else if (com == 1){Console.WriteLine("电脑出剪刀,你出布,你输了");}else if (com == 2){Console.WriteLine("电脑出布,你出布,平手");}break;}}}#endregion

 

转载于:.html

更多推荐

C#入门篇5

本文发布于:2024-03-05 20:12:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1713286.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:入门篇

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!