阶乘的计算方法,范围1-10000
1 package com.gtja.gmall.eplusmall.entity; 2 3 import java.math.BigDecimal; 4 import java.util.Scanner; 5 6 /** 7 * Created by CP_wangchao on 2017/6/21. 8 */ 9 public class Test { 10 public static void main(String arg[]){ 11 Scanner scanner = new Scanner(System.in); 12 int index = scanner.nextInt(); 13 System.out.print(fun(index)); 14 } 15 16 public static BigDecimal fun(long index){ 17 18 BigDecimal sum = new BigDecimal("1"); 19 for(int i=1;i<=index;i++){ 20 sum = sum.multiply(new BigDecimal(String.valueOf(i))); 21 } 22 return sum; 23 } 24 }