Java中计算大数的阶乘

来源:互联网 发布:心事某人知 编辑:程序博客网 时间:2024/05/17 05:10
import java.math.BigInteger;
import java.util.Scanner;
class Main {//
 public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    while(sc.hasNext()){
     int n = sc.nextInt();
     BigInteger sum =new BigInteger("1");
     while(n>1){
      sum = sum.multiply(new BigInteger(""+(n--)+""));
     }
     System.out.println(sum);
    }//end while 
  }//end  main
}
原创粉丝点击