**Problem 40:**

An irrational decimal fraction is created by concatenating the positive integers:

0.123456789101112131415161718192021…

It can be seen that the 12^{th} digit of the fractional part is 1.

If *d*_{n} represents the *n*^{th} digit of the fractional part, find the value of the following expression.

*d*_{1} x *d*_{10} x *d*_{100} x *d*_{1000} x *d*_{10000} x *d*_{100000} x *d*_{1000000}

**Idea:**

While overkill on the number of digits, I figured (at the time) it would be easiest to just append the numbers 1 – 1 million in a String (although I could’ve checked the length after each append, I didn’t think it was worth it, unless I ran into a buffer overflow error of some sort, but I didn’t). Then it was just a matter of multiplying the specified index digits together.

long answer = -1; StringBuilder sb = new StringBuilder(); int i = 1; while(sb.length() < 1000000) { sb.append(i); i++; } i = 1; long val = Integer.parseInt(""+sb.charAt(i-1)); i*=10; while(i <= 1000000) { val *= Integer.parseInt(""+sb.charAt(i-1)); i*=10; } answer = val; System.out.println("Answer: "+answer);