本文介绍了递归和迭代之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在java中搜索递归和迭代之间的区别。请包含两者的Java代码示例。

I am searching for the difference between recursion and iteration in java. Please include a Java code example of both.

2.如果我在android中收到消息,我怎样才能打开我的打开的应用程序?

2.How can i open my open application only if i receive message in android?


  1. 如何关闭设备中运行的第三方服务?


推荐答案

当方法或函数在其原始参数的子集上调用自身时,就会发生递归。例如,MergeSort - 它将数组拆分为两半并在这两半中调用自身。

Recursion happens when a method or function calls itself on a subset of its original argument. For example, MergeSort - it splits the array into two halves and calls itself on these two halves.

递归看起来像这样,但它是一个非常人为的例子类似于下面的迭代示例:

Recursion would look like this, but it is a very artificial example that works similarly to the iteration example below:

public void doSomething(int i) {
    // code
    if (i == 10) {
        return;
    } else {
        doSomething(i + 1);
    }
}

迭代是循环或循环的一次传递。例如,此循环中的代码:

Iteration is one pass of a cycle or loop. For example, code in this loop:

for(int i = 0; i < 10; i++){
    //code
}

将执行10次,即有10次迭代。

will be executed 10 times, i.e. have 10 iterations.

这篇关于递归和迭代之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 01:39