
package com.etc;
/**
* 1、使用递归求n!
*
* @author Administrator
* 1,使用for循环算出 5!
* 5! 5*4! 4! 4*3! 3 3*2! 2 2*1! 1!=1;
*/
public class Test3 {
public static void main(String[] args) {
int k = fn(5);
System.out.println(k);
}
public static int fn(int n) {
int num = 1;
if (n==1){
return 1;
}
else {
return n*fn(n-1);
}
}
}



初级程序员
by: 雨落冬夜 发表于:2017-04-19 12:03:04 顶(0) | 踩(0) 回复
不错
回复评论