递归求阶乘和循环阶乘

public class Factorial {
static long sum=0;
static long factorial=1;
public static void main(String [] args){
	java.util.Scanner in = new java.util.Scanner(System.in);
	int count = in.nextInt();
	for(int a=1; a<=count; a++){
	factorial=factorial*a;
	}
	System.out.println(factorial);
}
}
/*递归求阶乘*/
public class RecursionRequestFactorial {
public long factorial(int request_number){
	long value=0;
	if(request_number ==1 || request_number ==0){
		value =1;
	}else if(request_number > 1){
		value= request_number*factorial(request_number-1);
	}
	return value;
}
public static void main(String [] args){
	java.util.Scanner in = new java.util.Scanner(System.in);
	int request_number = in.nextInt();
	RecursionRequestFactorial start = new RecursionRequestFactorial();
	System.out.println(start.factorial(request_number));
}
}



阅读更多
文章标签: string class
个人分类: JAVA
上一篇java使用冒泡法排序
下一篇做的练习题,输入整数,逆序输出,并输出位数。
想对作者说点什么? 我来说一句

VB 递归阶乘

2010年06月07日 36KB 下载

没有更多推荐了,返回首页

关闭
关闭