Project Euler #20: Factorial digit sum

  • + 0 comments

    java

    BigInteger mult = new BigInteger("1");
            BigInteger sum = new BigInteger("0");
            for (int i = 2; i <= num; i++) {
                mult = mult.multiply(new BigInteger(String.valueOf(i)));
            }
            String sMult = String.valueOf(mult);
            for (int i = 0; i < sMult.length(); i++) {
                String arg = String.valueOf(sMult.charAt(i));
                sum = sum.add(new BigInteger(arg));
            }
            System.out.println(sum);