Java程序打印给定数字的阶乘
正整数n的阶乘是从n到1的所有值的乘积。例如,阶乘3是(3*2*1=6)。
算法
1. Take integer variable A 2. Assign a value to the variable 3. From value, A up to 1 multiply each digit and store 4. The final stored value is factorial of A
示例
import java.util.Scanner;
public class Factorial {
public static void main(String args[]){
int i, factorial=1, number;
System.out.println("输入您需要查找阶乘的数字:");
Scanner sc = new Scanner(System.in);
number = sc.nextInt();
for(i = 1; i<=number; i++) {
factorial = factorial * i;
}
System.out.println("Factorial of the given number is:: "+factorial);
}
}输出结果
输入您需要查找阶乘的数字: 25 Factorial of the given number is:: 2076180480
热门推荐
10 闺蜜好运祝福语简短
11 离别祝福语简短送同事
12 欢天喜地盖新房祝福语简短
13 新年的祝福语简短的
14 富豪奶奶生日祝福语简短
15 收围巾的祝福语简短
16 结婚祝福语简短精辟横幅
17 猪年元旦祝福语简短创意
18 孩子满月随礼简短祝福语