Tag Archives: googol

Euler Problem 56

Easy. Used BigInteger class and long variables just to be on the safe side. Didn’t need to be. Small answer.

    import java.math.*;

    public class Euler56
    {
        public static void main(String[] args)
        {
            Euler56 e = new Euler56();
            System.out.format(“Problem: %s\n”, e.getClass().getName());
            System.out.format(“Answer = %s\n”, e.Problem());
        }
        public String Problem ()
        {
            long max = 0;
            for (int a = 1; a < 100; a++)
                for (int b = 1; b  max)
                        max = GooSum;
                }
            return String.valueOf(max);
        }
        public long digitalSum(String number)
        {
            long sum = 0;
            for (int n = 0; n <= number.length()-1; n++)
                sum += (number.charAt(n)-48);
            return sum;
        }
    }