java递归方法好吗_哪个在Java中更快,还是使用递归方法?

我有以下两个方法的示例类:

Process.java:

public class Process {

public Process() {

}

public static void countRecursive(int num) {

System.out.println("countRecursive: " + num++);

if (num <= 10) countRecursive(num);

else return;

}

public static void countWhile(int num) {

do System.out.println("countWhile: " + num++);

while (num <= 10);

}

}

主班:

public static void main(String[] args) {

Process.countRecursive(0);

Process.countWhile(0);

}

输出:

countRecursive: 0

countRecursive: 1

countRecursive: 2

countRecursive: 3

countRecursive: 4

countRecursive: 5

countRecursive: 6

countRecursive: 7

countRecursive: 8

countRecursive: 9

countRecursive: 10

countWhile: 0

countWhile: 1

countWhile: 2

countWhile: 3

countWhile: 4

countWhile: 5

countWhile: 6

countWhile: 7

countWhile: 8

countWhile: 9

countWhile: 10

但是我想知道推荐使用哪种“技术”,为什么。

提前致谢。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值