zoukankan      html  css  js  c++  java
  • Console算法[if,Function]一用递归的方式代替循环语句

    ylbtech-Arithmetic:Console-算法[if,Function]-一用递归的方式代替循环语句
     
    1.A,Demo(案例)

     用递归的方式代替循环语句

    1.B,Solution(解决方案)
    1.B.1,方式一
    using System;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                int i = 0;
                int length = 10;
                Write(i,length);
            }
            static void Write(int i, int length)
            {
    
                if (i <= length)
                {
                    Console.WriteLine("数字" + i);
                    i++;
                    Write(i, length);
                }
            }
           
        }
       
    }
    1.B.2,方式二
    using System;
    namespace ConsoleApplication1
    {
        class Programe
        {
            /// <summary>
            /// ylb: 算法
            /// 用递归的方式代替循环语句
            /// </summary>
            /// <param name="args"></param>
            static void Main(string[] args)
            {
                int number = 10;    //循环的次数,10次
                int count = 1;  //累计次数,初始值为 1
    
                Write(number, count);
            }
            static void Write(int number, int count)
            {
                if (count <= number)
                {
                    Console.WriteLine(count);
                    count++;
                    Write(number, count);
                }
            }
        }
    }
    1.C,Execution Result(运行结果)
     
    warn 作者:ylbtech
    出处:http://ylbtech.cnblogs.com/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    inline-block 文字与图片不对齐
    js去除数组重复项
    react2
    kfaka windows安装
    sigar 监控服务器硬件信息
    Disruptor
    Servlet 3特性:异步Servlet
    jvmtop 监控
    eclipse如何debug调试jdk源码
    一致性hash算法
  • 原文地址:https://www.cnblogs.com/ylbtech/p/3113484.html
Copyright © 2011-2022 走看看