hdu 1042 N! (求 n 的阶乘)
http://acm.hdu.edu.cn/showproblem.php?pid=1042
View Code
1 // 大整数的加减乘除 两个数必须都是 BigInteger 类 2 import java.util.*; 3 import java.math.*; 4 public class Main{ 5 6 public static void main(String args[]){ 7 8 Scanner cin = new Scanner(System.in) ; 9 10 11 12 while(cin.hasNextInt()){ 13 String str = cin.next(); // BigInteger 将 字符串转化为 大整数 14 BigInteger a = new BigInteger("1") ; 15 16 BigInteger i = new BigInteger("1") ; 17 BigInteger num = new BigInteger(str) ; 18 BigInteger one = new BigInteger("1") ; 19 20 21 22 while(i.compareTo(num) <= 0){ //比较是 两个大整数,, 23 24 a = a.multiply(i) ; 25 i = i.add(one); 26 27 28 } 29 System.out.println(a) ; 30 31 32 33 } 34 } 35 36 }