• 寒假作业(1)


     1.输入三个整数,xyz,最终以从小到大的方式输出。利用if嵌套。
                Console.Write("请输入x:");
                int x = int.Parse(Console.ReadLine());
                Console.Write("请输入y:");
                int y = int.Parse(Console.ReadLine());
                Console.Write("请输入z:");
                int z = int.Parse(Console.ReadLine());
                if (x <= y && x <= z)
                {
                    Console.WriteLine(x);
                    if (y <= z)
                    {
                        Console.WriteLine(y);
                        Console.WriteLine(z);
                    }
                    else
                    {
                        Console.WriteLine(z);
                        Console.WriteLine(y);
                    }
                }
                else if (y <= x && y <= z)
                {
                    Console.WriteLine(y);
                    if (x <= z)
                    {
                        Console.WriteLine(x);
                        Console.WriteLine(z);
                    }
                    else
                    {
                        Console.WriteLine(z);
                        Console.WriteLine(x);
                    }
                }
                else //z是最小的
                {
                    Console.WriteLine(z);
                    if (x <= y)
                    {
                        Console.WriteLine(x);
                        Console.WriteLine(y);
                    }
                    else
                    {
                        Console.WriteLine(y);
                        Console.WriteLine(x);
                    }
                }
                Console.ReadLine();


    2.输入三个整数,xyz,最终以从小到大的方式输出。利用中间变量。
                最终的输出语句是
                Console.WriteLine(x+"、"+y+"、"+z);
                Console.WriteLine("请输入x");
                int x = int.Parse(Console.ReadLine());
                Console.WriteLine("请输入y");
                int y = int.Parse(Console.ReadLine());
                Console.WriteLine("请输入z");
                int z = int.Parse(Console.ReadLine());
                int a = 0;
                int b = 0;
                int c = 0;
                if (x > y)
                {
                    a = x;
                    x = y;
                    y = a;
                }
                if (x > z)
                {
                    b = x;
                    x = z;
                    z=b;
                }
                if (y > z)
                {
                    c = y;
                    y = z;
                    z = c;
                }
                Console.WriteLine(x);
                Console.WriteLine(y);
                Console.WriteLine(z);
                Console.ReadLine();

                    }
                }
                Console.ReadLine();

    3.输入三个整数,xyz,最终以从小到大的方式输出。利用条件运算符。
                      ?   :
                问前面的表达式成立不成立,若成立得到冒号前面对的值
                若不成立,得到冒号后面的值

                Console.Write("请输入x");
                int x = int.Parse(Console.ReadLine());
                Console.Write("请输入y");
                int y = int.Parse(Console.ReadLine());
                Console.Write("请输入z");
                int z = int.Parse(Console.ReadLine());
                int a = (x <= y && x <= z) ? 1 : 2;
                if (a == 1)
                {
                    if (y <= z)
                    {
                        Console.WriteLine(x + "<" + y + "<" + z);
                    }
                    else
                    {
                        Console.WriteLine(x + "<" + z + "<" + y);
                    }
                }
                else
                {
                    int b = (y <= x && y <= z) ? 1 : 2;
                    if (b == 1)
                    {
                        if (x <= z)
                        {
                            Console.WriteLine(y + "<" + x + "<" + z);
                        }
                        else
                        {
                            Console.WriteLine(y + "<" + z + "<" + x);
                        }
                    }
                    else
                    {
                        if (x <= y)
                        {
                            Console.WriteLine(z + "<" + x + "<" + y);
                        }
                        else
                        {
                            Console.WriteLine(z + "<" + y + "<" + x);
                        }
                    }
                }
                Console.ReadLine();


                4.“现在几点了?”键盘键入小时数,判断是上午am还是下午pm。
                打印出来现在是上午几点还是下午几点。利用条件运算符。
                Console.Write("请输入时间:");
                int t = int.Parse(Console.ReadLine());
                if (t >= 0 && t <= 24)
                {
                    string a = (t > 12) ? ((t - 12) + "p.m.") : (t + "a.m.");
                    Console.WriteLine(a);
                }
                else
                {
                    Console.WriteLine("输入时间有误!");
                }
                Console.ReadLine();

                5.相亲过程:你有房子么?你有钱么?你有能力么?
                【结婚吧】【先买房子再结婚】【先赚钱再买房子再结婚】都没有【拜拜~~】
                利用if嵌套做相亲过程。
                Console.WriteLine("你有房子么?");
                string a = Console.ReadLine();
                if (a == "有")
                {
                    Console.WriteLine("咱们结婚吧!");
                }
                else if (a == "没有")
                {
                    Console.WriteLine("你有钱么?");
                    string b = Console.ReadLine();
                    if (b == "有")
                    {
                        Console.WriteLine("先买房,再结婚");
                    }
                    else if (b == "没有")
                    {
                        Console.WriteLine("你有能力么?");
                        string c = Console.ReadLine();
                        if (c == "有")
                        {
                            Console.WriteLine("先赚钱再买房再结婚");
                        }
                        else if (c == "没有")
                        {
                            Console.WriteLine("拜拜!");
                        }
                        else
                        {
                            Console.WriteLine("输入有误!");
                        }
                    }
                    else
                    {
                        Console.WriteLine("输入有误!");
                    }
                }
                else
                {
                    Console.WriteLine("输入错误!");
                }
                Console.ReadLine();

  • 相关阅读:
    JS之AJAX篇FormData对象
    JS之AJAX进度事件
    JS之BOM篇navigator对象
    JS之AJAX响应解码
    JS之AJAXXHR对象
    SAP NetWeaver平台介绍
    图解SSIS批量导入Excel文件(转)
    SQL Server 2008安装图解(转)
    实施BI应该如何找准切入点?
    如何修改SQL SA密码
  • 原文地址:https://www.cnblogs.com/panyiquan/p/5199188.html
Copyright © 2020-2023  润新知