/** * Problem 20 * * n! means n × (n − 1) × ... × 3 × 2 × 1 * Find the sum of the digits in the number 100! */ public void Problem120() throws Exception { BigInteger n = BigInteger.ONE; for (int i = 1; 100 >= i; i++) { n = n.multiply(BigInteger.valueOf(i)); } System.out.println(100 + "! = " + n); int sum = 0; String[] numbers = n.toString().split(""); for (int i = 1; i < numbers.length; i++) { sum += Integer.valueOf(numbers[i]).intValue(); } System.out.println(sum); }