条件语句实例

判断三个数谁对大:

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 + ",请做好开始准备");
            
        }

 

转载于:https://www.cnblogs.com/liuyudong0825/p/4696672.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值