赞
踩
例如:用递归实现n = 5*4*3*2*1
实现代码如下:
- public class Demo {
- public static void main(String[] args){
- fact(5);
- }
-
- public static int fact(int n) {
- if(n == 1){
- return 1;
- }else{
- return n*fact(n-1);
- }
- }
程序执行逻辑过程如下:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。