日期:2014-05-20 浏览次数:20868 次
import java.math.BigInteger; public class Test1 { public static void main(String[] args) { BigInteger sum = new BigInteger("0"); for (int i = 1; i <= 30; i++) { sum = sum.add(getResult(i)); } System.out.println("sum = " + sum); } public static BigInteger getResult(int num) { BigInteger result = new BigInteger("1");; for (int i = 1; i <= num; i++) { result = result.multiply(new BigInteger(String.valueOf(i))); } return result; } }