I'm trying to solve this problem
An irrational decimal fraction is created by concatenating the positive integers:
0.123456789101112131415161718192021...
It can be seen that the 12th digit of the fractional part is 1.
If dn represents the nth digit of the fractional part, find the value of the following expression.
d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000
Here is my code
public class Test
{
public static void main(String[] args)
{
String strNbr="";
for(long i=1;i<1000000;i++)
strNbr= strNbr + i;
//Find the digits
int d1=1,d10,d100,d1000,d10000,d100000,d1000000;
int product=0;
d10=Integer.parseInt(strNbr.substring(9, 10));
d100=Integer.parseInt(strNbr.substring(99, 100));
d1000=Integer.parseInt(strNbr.substring(999, 1000));
d10000=Integer.parseInt(strNbr.substring(9999, 10000));
d100000=Integer.parseInt(strNbr.substring(99999, 100000));
d1000000=Integer.parseInt(strNbr.substring(999999, 1000000));
product = d1 * d10 * d100 * d1000 * d10000 * d100000 * d1000000;
System.out.println(product);
}
}
I waited about 40 mins and the code showed no output :ehh:
I know the loop is so long and there must be a better method to do this, but I cant think of a better method than using a string to store the number, since using a integer or double would lead to an extremely large number and would be very hard to locate d10-d100-d1000....
so what do you think I should do to solve this problem?