zoukankan      html  css  js  c++  java
  • 条件语句

    猜拳

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 猜拳
    {
        class Program
        {
            static void Main(string[] args)
            {
                while (true)
                {
                    //用户输入石头剪子布,计算器也随机出一个石头剪子布,
                    //用户与计算机进行对比,得出胜负;
    
                    //1、用户输入选择的手势
                    Console.Write("请输入您的手势(石头:0,剪子:1,布:2):");
                    int yh = Convert.ToInt32(Console.ReadLine());
    
                    //2、计算机随机选出计算机的手势
                    Random r = new Random();
                    int dn = r.Next(0, 3);
    
                    //3、对比,输出结果
                    //石头0,剪子1,布2
                    //0 1 = -1
                    //1 2 = -1
                    //2 0 = 2
    
                    //0 2 = -2 
                    //1 0 = 1
                    //2 1 = 1
                    int jg = yh - dn;
                    if (jg == -1 || jg == 2)
                    {
                        Console.WriteLine("用户胜利!");
                    }
                    else if (jg == -2 || jg == 1)
                    {
                        Console.WriteLine("用户失败!");
                    }
                    else
                    {
                        Console.WriteLine("平局!");
                    }
                }
                Console.ReadLine();
            }
        }
    }

    随机数

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 随机数
    {
        class Program
        {
            static void Main(string[] args)
            {
                Random r = new Random();
    
                Console.WriteLine(r.Next(0, 1));
                Console.WriteLine(r.Next(0, 1));
                Console.WriteLine(r.Next(0, 1));
                Console.WriteLine(r.Next(0, 1));
                Console.WriteLine(r.Next(0, 1));
                Console.WriteLine(r.Next(0, 1));
                Console.WriteLine(r.Next(0, 1));
                Console.WriteLine(r.Next(0, 1));
                Console.WriteLine(r.Next(0, 1));
                Console.WriteLine(r.Next(0, 1));
    
    
                Console.ReadLine();
            }
        }
    }

    小练习:身高体重

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 条件语句练习
    {
        class Program
        {
            static void Main(string[] args)
            {
                //男士体重=身高-100+-3
                //女士体重=身高-110+-3
                //KG  CM
                //90  180
                //180-100 = 80
    
                //男士体重 - 男士身高 = -100+-3;
                //男士体重 - 男士身高 +100 =+-3;
    
    
                //内容输入
                Console.Write("请输入您的性别:");
                string x = Console.ReadLine();
                Console.Write("请输入您的身高(cm):");
                int g = Convert.ToInt32(Console.ReadLine());
                Console.Write("请输入您的体重(kg):");
                int z = Convert.ToInt32(Console.ReadLine());
    
                //数据运算+数据输出
                if (x == "")
                {
                    //男士体重=身高-100+-3
                    int bz = g - 100;
    
                    if (z > bz + 3)
                    {
                        Console.WriteLine("你偏胖了!");
                        Console.WriteLine("您超出了标准体重" + (z - (bz + 3)) + "公斤!");
                    }
                    else if (z < bz - 3)
                    {
                        Console.WriteLine("你偏瘦了!");
                        Console.WriteLine("您距离标准体重还差" + (bz - 3 - z) + "公斤!");
                    }
                    else if (z <= bz + 3 && z >= bz - 3)
                    {
                        Console.WriteLine("你身材很标准!继续保持!");
                    }
                }
                else if (x == "")
                {
                    //女士体重=身高-110+-3
                    int bz = g - 110;
                    if (z <= bz + 3 && z >= bz - 3)
                    {
                        Console.WriteLine("您身材很标准!继续保持!");
                    }
                    else if (z > bz + 3)
                    {
                        Console.WriteLine("您偏胖了!");
                    }
                    else
                    {
                        Console.WriteLine("您偏瘦了!");
                    }
                }
                else
                {
                    Console.WriteLine("性别输入有误!");
                }
    
                Console.ReadLine();
            }
        }
    }
  • 相关阅读:
    Spring源码解析 | 第一篇 :IntelliJ IDEA2019.3编译Spring5.3.x源码
    Mybatis和Mybatis-Plus时间范围查询,亲测有效
    Centos7增加磁盘空间并挂载目录(VMware)
    Docker添加TLS认证修复2375端口暴露引发的漏洞
    【动态规划】0-1背包问题原理和实现
    c#日期格式化(关于12小时制和24小时制)
    JS日期时间格式化
    子页面iframe如何调用 父页面的方法 或者对象(基于layui框架)
    js把文字复制到粘贴板
    理解sql server STUFF函数
  • 原文地址:https://www.cnblogs.com/tonyhere/p/5469763.html
Copyright © 2011-2022 走看看