java试题6,求整数n的阶乘

6、编写一个程序,求整数n的阶乘,例如5的阶乘是12345

package com;

import java.util.Scanner;

public class test2 {

	public static void main(String[] args) {
	
		 Scanner sc = new Scanner(System.in);
	        int i=sc.nextInt();
	        int sum = 1;
	        for(int x=1;x<=i;x++){
	        	sum = sum * x;
	        }
	        System.out.println(sum);
			
	}
}

你可能感兴趣的:(java试题6,求整数n的阶乘)