java递归实现阶乘factorial

public class jiecheng {
	static int result=1;
	
	public static int jiecheng(int n) {
		
		if (n==1) {
			
			return 1;
		}
		else
			return n*jiecheng(n-1);
		
//		if (n>0) {
//			result = result*n;
//			
//			n--;
//			
//			jiecheng(n);
//		}else {
//			return result;
//		}
		
		
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc =  new Scanner(System.in);
		
		int a = sc.nextInt();
		
//		System.out.println(a);
		int b = jiecheng(a);
		
		System.out.println(b);
		
		sc.close();

	}

}

猜你喜欢

转载自blog.csdn.net/onlyoncelove/article/details/81123588
今日推荐