zoukankan      html  css  js  c++  java
  • if练习随笔

    分支:——四种if
    一、
    if(条件表达式)
    {
    }

    二、
    if(条件表达式)
    {
    }
    else
    {
    }

    三、
    if(条件表达式)
    {
    }
    else if(条件表达式)
    {
    }
    else if(条件表达式)
    {
    }
    ....
    else
    {
    }

    四、
    if(条件表达式)
    {
     if(条件表达式)
     {
     }
     .....
    }
    else
    {
     if(条件表达式)
     {
     }
     .....
    }

    作业:1.输入年、月、日,判断输入的日期格式是否正确

    static void Main1(string[] args)
            {
                Console.WriteLine("输入年份");
                int year = Convert.ToInt32(Console.ReadLine());
                if (year >= 1 && year <= 9999)
                {
                    Console.WriteLine("输入月份");
                    int month = Convert.ToInt32(Console.ReadLine());
                    if (month >= 1 && month <= 12)
                    {
                        if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
                        {
                            Console.WriteLine("输入日期");
                            int day = Convert.ToInt32(Console.ReadLine());
                            if (day >= 1 && day <= 31)
                            {
                                Console.WriteLine(year + "" + month + "" + day + "");
                            }
                            else
                            {
                                Console.WriteLine("错误,大月只能在1-31之间");
                            }
                        }
                        else if (month == 4 || month == 6 || month == 9 || month == 11)
                        {
                            Console.WriteLine("输入日期");
                            int day = Convert.ToInt32(Console.ReadLine());
                            if (day >= 1 && day <= 30)
                            {
                                Console.WriteLine(year + "" + month + "" + day + "");
                            }
                            else
                            {
                                Console.WriteLine("错误,小月只能在1-30之间");
                            }
                        }
                        else if (month == 2)
                        {
                            Console.WriteLine("输入日期");
                            int day = Convert.ToInt32(Console.ReadLine());
                            if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0))
                            {
                                if (day >= 1 && day <= 29)
                                {
                                    Console.WriteLine(year + "" + month + "" + day + "");
                                }
                                else
                                {
                                    Console.WriteLine("打印:错误,闰年2月只能在1-29之间");
                                }
                            }
                            else
                            {
                                if (day >= 1 && day <= 28)
                                {
                                    Console.WriteLine(year + "" + month + "" + day + "");
                                }
                                else
                                {
                                    Console.WriteLine("打印:错误,平年2月只能在1-28之间");
                                }
                            }
                        }
                    }
                }
                else
                {
                    Console.WriteLine("打印年错误");
                }
            }

    2.做猜拳的游戏。
    0-剪刀,1-石头,2-布

    static void Main(string[] args)
            {
                Random rand = new Random();
                int computer = rand.Next(3);
                Console.Write("猜拳游戏,0-剪刀,1-石头,2-布
    请出拳:");
                int ren = Convert.ToInt32(Console.ReadLine());
                if (ren == 0) //人出剪刀
                {
                    if (computer == 0)
                    {
                        Console.WriteLine("平局");
                    }
                    else if (computer == 1)
                    {
                        Console.WriteLine("你输了");
                    }
                    else if (computer == 2)
                    {
                        Console.WriteLine("你赢了");
                    }
                }
                else if (ren == 1) //人出石头
                {
                    if (computer == 0)
                    {
                        Console.WriteLine("你赢了");
                    }
                    else if (computer == 1)
                    {
                        Console.WriteLine("平局");
                    }
                    else if (computer == 2)
                    {
                        Console.WriteLine("你输了");
                    }
                }
                else if (ren == 2) //人出布
                {
                    if (computer == 0)
                    {
                        Console.WriteLine("你输了");
                    }
                    else if (computer == 1)
                    {
                        Console.WriteLine("你赢了");
                    }
                    else if (computer == 2)
                    {
                        Console.WriteLine("平局");
                    }
                }
                else
                {
                    Console.WriteLine("你别乱出");
                }
            }
  • 相关阅读:
    内网很安全?错错错!附攻击演示
    Fiddler无所不能——之测试开发攻城狮必备利器
    【橙子独创】【假设前置数据异常法】案列解析
    偶发异常BUG,如何高效精准分析排查定位?
    史上最全提现模块案例分解
    移动端推送测试涉及点
    模拟导入系统通讯录5000+手机号 校验批量数据处理是否正常?
    发散逆向思维之查询类列表测试范围的思考
    PICT工具一键生成正交试验用例
    据说黑白红客大多是出身测试行业,那么前戏如何做好呢?戳下
  • 原文地址:https://www.cnblogs.com/languang/p/4476289.html
Copyright © 2011-2022 走看看