• 假期作业1-5


    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 
    {
    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();


    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();

  • 相关阅读:
    移动端HTML5音频与视频问题及解决方案
    git did not exit cleanly
    移动端事件对象touches的误区
    原创:CSS3技术-雪碧图自适应缩放与精灵动画方案
    H5+JS+CSS3 综合应用
    深入理解CSS3 Animation 帧动画
    在 MacOS 中使用 multipass 安装 microk8s 环境
    [译] Design patterns for container-based distributed systems
    Sangmado 公共基础类库
    Redola.Rpc 集成 Consul 服务发现
  • 原文地址:https://www.cnblogs.com/cycanfly/p/5199222.html
Copyright © 2020-2023  润新知