• 分支语句嵌套练习


    练习

    1、男士体重 = 身高 - 100 (+-3)
    女士体重 = 身高 - 110 (+-3)
    请输入性别:
    请输入体重(kg):
    请输入身高(cm):

    您的体重非常标准/您需要减肥了/您需要补充营养

    您距离标准体重还差xxx公斤

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 分支语句嵌套练习1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.Write("请输入性别:(男/女)");
                string a = Console.ReadLine();
    
                Console.Write("请输入体重:(公斤)");
                decimal t = Convert.ToDecimal(Console.ReadLine());
    
                Console.Write("请输入身高:(厘米)");
                decimal g = Convert.ToDecimal(Console.ReadLine());
    
                string n = "";
                if (n == a)
                {         
    
    
                    if ((t == g - 100) || (t == g - 101) || (t == g - 102) || (t == g - 103) || (t == g - 99) || (t == g - 98) || t == g - 97)
                    {
    
    
    
                        Console.Write("您的体重非常标准了");
    
    
                    }
    
                    else if (t < g - 103)
                    {
    
                        Console.Write("您需要补充营养了,你距离标准体重还差" + (g - 103 - t) + "公斤");
                    }
    
                    else if (t > g - 97)
                    {
    
                        Console.Write("您需要减肥了,你距离标准体重还差" + (t - (g - 97) ) + "公斤");
    
                    }
    
    
                }
                else
                {
                    if ((t == g - 110) || (t == g - 111) || (t == g - 112) || (t == g - 113) || (t == g - 109) || (t == g - 108) || t == g - 107)
                    {
    
    
    
                        Console.Write("您的体重非常标准了");
    
    
                    }
    
                    else if (t < g - 113)
                    {
    
                        Console.Write("您需要补充营养了,你距离标准体重还差" + (g - 113 - t) + "公斤");
                    }
    
                    else if (t > g - 107)
                    {
    
                        Console.Write("您需要减肥了,你距离标准体重还差" + (t - (g - 107) ) + "公斤");
    
                    }
    
    
                }
    
    
                //身高-100(+—3) b=g-100(+-3)
    
                //您的体重非常标准了  您需要减肥了  您需要补充营养了
                //你距离标准体重还差xx公斤
    
                
    
    
    
                Console.ReadLine();
            }
        }
    }

    2、24时转为12时
    让用户输入一个 24时制的时间,比如:
    请输入小时: 14
    请输入分钟: 33

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace 练习二
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.Write("请输入小时:");
                int xh = Convert.ToInt32(Console.ReadLine());
                Console.Write("请输入分钟:");
                int fz = Convert.ToInt32(Console.ReadLine());
    
                if (xh >= 0 && xh < 24)
                {
                    if (fz >= 0 && fz < 60)
                    {
                        if (xh > 12)
                        {
                            Console.Write("下午"+(xh-12)+":"+fz);
                        }
                        else 
                        {
                            Console.Write("上午"+xh+":"+fz);
                        }
                    }
                    else 
                    {
                        Console.WriteLine("分钟输入错误!");
                    }
                }
                else 
                {
                    Console.WriteLine("小时输入错误!");
                }
    
    
                Console.ReadLine();
    
    
    
    
    
    
                //24时转为12时  请输入一个24时制的时间  请输入小时: 请输入分钟:
            }
        }
    }
  • 相关阅读:
    触发事件trigger
    淘宝天猫关键词SEO优化
    Linux下升级python
    python3多线程趣味详解
    python之selenium
    1kkk
    python之lxml(xpath)
    python中时间日期格式化符号
    唯品会数据采集-异步瀑布流
    python数据库操作pymysql
  • 原文地址:https://www.cnblogs.com/songfengyao/p/5515244.html
Copyright © 2020-2023  润新知