java方法递归调用【详细解释(解决什么问题、递归执行机制等)】

  1. 方法递归调用(Method recursive invoking)
    1. 递归:递归是一个在数学和计算机科学中广泛使用的概念,它描述了一种特殊的过程或方法,即一个函数、过程或算法在其定义或执行过程中直接或间接地调用自身。递归通常用于将一个复杂的大型问题分解为与原问题相似但规模更小的子问题来求解,从而达到简化问题并找到解决方案的目的。
  1. 在Java中,递归是一种编程技术,它涉及到一个函数(或方法)在其定义中直接或间接地调用自身。通常用于解决那些可以分解为更小、相似子问题的问题。递归的基本思想是将一个复杂的问题分解为两个或多个更小的相同问题,直到这些更小的问题变得简单到可以直接解决。当这些小问题被解决时,它们的解决方案被组合起来,形成原始问题的解决方案。
    1. 递归就是方法自己调用自己,每次调用时传入不同的变量。

(Recursion is when a method calls itself, passing in a different variable each time it is called)

    1. 递归有助于编程者解决复杂问题,同时可以让代码变得简洁

(Recursion helps programmers solve complex problems while keeping code concise)

    1. 可以解决各种数学问题
      1. 8皇后问题,汉诺塔,阶乘问题,迷宫问题,球和篮子的问题
      2. 各种算法中也会使用到递归,e.g快排,归并排序,二分查找,分治算法等
      3. 将用栈解决的问题-->递归代码比较简洁

  1. 递归调用的本质(方法的调用)Recursive calls are essentially method calls

  1. 方法递归调用(Method recursive call)
  1. 递归重要规则(Recursive important rules)
  1. 执行一个方法时,就创建一个新的受保护的独立空间(栈空间)

(When a method is executed, a new protected independent space (stack space) is created.)

  1. 方法的局部变量是独立的,不会相互影响,比如n变量

(The local variables of a method are independent and do not affect each other, such as the n variable)

  1. 如果方法中使用的是引用类型变量(比如数组,对象),就会共享该引用类型的数据

(If a method uses a reference type variable (such as an array, object), the data of that reference type is shared)

  1. 递归必须向退出递归的条件逼近,否则就是无限递归,出现(StackOverflowError,死龟了:)

(Recursion must approximate the condition of exit recursion, otherwise it is infinite recursion)

  1. 当一个方法执行完毕,或者遇到return,就会返回,遵守谁调用,就将结果返回给谁,同时当方法执行完毕或者返回时,该方法也就执行完毕

(When a method finishes executing, or encounters a return, it returns, the result is returned to whoever calls it, and when the method finishes executing or returning, the method finishes executing)

  • 6
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值