zoukankan      html  css  js  c++  java
  • 练习: C#---函数(篮球弹起高度、等腰三角形)

    /// <summary>
    /// 1、篮球从20米高度落地,弹起高度是上次的3/4,
    ///    输入次数算出高度(有参数,有返回值)
    /// </summary>
    /// <param name="times"></param>
    /// <returns></returns>
            public double basketball (int times)
            {
                double height=20.0;
                for (int i = 1; i <= times;i++ )
                {
                    height *= (double)3/4;
                    Console.WriteLine("篮球弹起第"+i+"次的高度为:"+height+"");
                }
                return height;
            }
         static void Main(string[] args)
            {
                Program hanshu = new Program();
    
                Console.Write("请输入弹起次数:");
                int times = int.Parse(Console.ReadLine());
                hanshu.basketball(times);
                Console.ReadLine();
    }

    /// <summary>
    /// 2、打印等腰三角形
    /// </summary>
            public void sanjiaoxing() 
            {
                Console.Write("请输入行数:");
                int hang = int.Parse(Console.ReadLine());
                for (int i = 1; i <= hang;i++ )//控制行
                {
                    for (int j = hang-1; j >=i;j-- ) //左边空格三角形
                    {
                        Console.Write(" ");
                    }
                    for (int x = 1; x <= 2 * i - 1;x++ )//右边等腰三角形
                    {
                        Console.Write("@");
                    }
                    Console.WriteLine();
                }
            }
         static void Main(string[] args)
            {
                Program hanshu = new Program();
                hanshu.sanjiaoxing();
                Console.ReadLine();
    
            }

  • 相关阅读:
    ISC DHCP: Enterprise grade solution for configuration needs
    The most widely used name server software: BIND
    不是技术牛人,如何拿到国内IT巨头的Offer--转
    NVIDIA---CUDA
    BIOS
    Computer form factor
    OC-常见错误 方法与函数的区别
    OC-面向对象
    OC-基本
    C-结构体、枚举
  • 原文地址:https://www.cnblogs.com/xiao55/p/5491377.html
Copyright © 2011-2022 走看看