java从键盘上录入任何整数,输出该整数的阶乘
import java.util.Scanner;/*** java从键盘上录入任何整数,输出该整数的阶乘*/
public class Test24 {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.println("请输入一个整数:");int num = sc.nextInt();//factorial中文意思是阶乘int factorial = 1;for (int i = 1;i<=num;i++){factorial*=i;}System.out.println(num+"的阶乘为:"+factorial);sc.close();}
}
执行代码如下: