All pastes #467449 Raw Edit

Anonymous

public java v1 · immutable
·published 2007-05-02 14:57 UTC
rendered paste body
/**     * Problem 20     *     * n! means n × (n &#8722; 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);    }