We shall say that an

n-digit number is pandigital if it makes use of all the digits 1 tonexactly once; for example, the 5-digit number, 15234, is 1 through 5 pandigital.The product 7254 is unusual, as the identity, 39 186 = 7254, containing multiplicand, multiplier, and product is 1 through 9 pandigital.

Find the sum of all products whose multiplicand/multiplier/product identity can be written as a 1 through 9 pandigital.

HINT: Some products can be obtained in more than one way so be sure to only include it once in your sum.

import java.util.*;public class Euler32

{

public static void main(String[] args)

{

System.out.print(“Problem 32:\n”);

Euler32 e = new Euler32();

System.out.print(“Answer = ” + e.Problem()+ “\n”);

}

public String Problem ()

{

ArrayList<Integer> p = new ArrayList<Integer>();

String [] digits = {“1″,”2″,”3″,”4″,”5″,”6″,”7″,”8″,”9”};

String num = “”;

boolean flag = true;

int len = 0;

int sum = 0;

for (int a = 1; a <= 4000; a++)

{

for (int b = 1; b <= 4000; b++)

{

num = String.valueOf(a)+String.valueOf(b)+String.valueOf(a*b);

len = num.length();

flag = true;

if (num.contains(“0”) == false && len == 9)

{

for (String d: digits)

{

if (num.replace(d, “”).length() != len -1)

flag = false;

}

if (flag)

{

if (p.contains(a*b) == false)

p.add(a*b);

System.out.format(“%s\n”, num);

}

}

}

}

for (int n: p)

sum +=n;

return String.valueOf(sum);

}

}