简单的For循环练习4(求5的阶乘)

/*
需求:求5的阶乘

什么是阶乘呢?
	n! = n*(n-1)! 规则
	n! = n*(n-1)*(n-2)*()*...3*2*1

求阶乘思想

*/

class ForDemo5{
	public static void main(String[] args){
		//定义最终结果变量
		int jc = 1;
		
		for(int x = 1;x<=5;x++){
			jc = jc * x;
		}
		System.out.println("5的阶乘是:"+jc);
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_42322406/article/details/89479281
今日推荐