`
yangyiqian
  • 浏览: 115148 次
  • 来自: ...
社区版块
存档分类
最新评论

迭代与递归

    博客分类:
  • JAVA
 
阅读更多
public class Test {

public int f1(int n) {
int result = 1;
while (n > 1) {
result *= n;
--n;
}

return result;
}

public static int f2(int n) {
if (n == 1)
return 1;

else
return n * f2(n - 1);

}

public static void main(String[] args) {
Test t = new Test();
System.out.println(new Date());
t.f1(999999999);
System.out.println(new Date());


}

}



以上代码充分说明,迭代在性能上以及稳定性上要好于递归调用
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics