阶乘计算
程序员文章站
2022-03-09 16:11:25
...
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[] value = new int[9999];
value[0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < value.length-1; j++) {
value[j] = value[j] * i;
}
for (int j = 0; j < value.length-1; j++) {
value[j+1] = value[j+1] + (value[j]/10);
value[j] = value[j] % 10;
}
}
int index = 0;
for (int i = value.length-1; i >= 0; i--) {
if(value[i] != 0) {
index = i;
break;
}
}
for (int i = index; i >= 0; i--) {
System.out.print(value[i]);
}
}
}