条件语句实例
2015-08-02 20:38
169 查看
判断三个数谁对大:
判断一个数的奇偶性:
判断闰年:
移动客服:
游戏随即英雄选择:
static void Main(string[] args) { Console.WriteLine("请输入第一个数:"); int a = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("请输入第二个数:"); int b = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("请输入第三个数:"); int c = Convert.ToInt32(Console.ReadLine()); if (a >= b) { if (a >= c) { Console.WriteLine("三个数最大的是:" + a); } else { Console.WriteLine("三个数最大的是:" + c); } } else { if (b >= c) { Console.WriteLine("三个数最大的是" + b); } else { Console.WriteLine("三个数最大的是" + c); } } }
判断一个数的奇偶性:
static void Main(string[] args) { Console.Write("输入一个数:"); int a = int.Parse(Console.ReadLine()); if (a%2== 0) { Console.Write("这个数是偶数"); } else { Console.Write("这个数是奇数"); } Console.ReadLine(); }
判断闰年:
static void Main(string[] args) { Console.WriteLine("请输入年份:"); int year = int.Parse(Console.ReadLine()); if (year % 400 == 0 || year % 4 == 0 && year % 4 != 0) { Console.Write(year + "是闰年"); } else { Console.Write(year+"是平年"); } }
移动客服:
static void Main(string[] args) { Console.WriteLine("查话费按1,查流量按2,人工服务按3,业务办理按4,"); int a = Convert.ToInt32(Console.ReadLine()); switch (a) { case 1: { Console.WriteLine("你的话费有点多,禁止充值"); break; } case 2: { Console.WriteLine("流量还可以支撑"); break; } case 3: { Console.WriteLine("人工服务全忙,请稍候"); break; } case 4: { Console.WriteLine("对不起不能办理"); break; } default: { Console.WriteLine("您输入的有误"); break; } } }
游戏随即英雄选择:
static void Main(string[] args) { Random a = new Random(); int b = a.Next(5); string hero; switch (b) { case 1: { hero = "伊泽瑞尔"; break; } case 2: { hero = "拉克丝"; break; } case 3: { hero = "盖伦"; break; } case 4: { hero = "提莫"; break; } default: { hero = "崔丝塔娜"; break; } } Console.WriteLine("你选的英雄为:" + hero + ",请做好开始准备"); }
相关文章推荐
- 宽带离网用户分析(1) 任务介绍
- HDOJ 1283 最简单的计算机
- Ubuntu下搭建FTP服务器
- (转)jQuery设计思想
- Snail—算法学习之内部排序
- 关于Posix的信号量
- 写一个函数,计算4 000 000 000 以内的最大的那个f(n)=n的值
- B样条绘制
- Android Studio使用OpenCV后,使APP不安装OpenCV Manager即可运行
- FZU 2183 字符串处理
- Mybatis: $与#的区别
- C#-基础加强(2)
- 多态
- Leetcode|Combination Sum III[回溯]
- Hdu 1 402 FFT 大整数相乘 && Hoj10005
- 设计模式三——单一职责原则
- Jenkins on PaaS
- Newton-Raphson方法
- Service和Thread的关系
- win8.1通过update升级win10的一些问题和思考