# small factorial help..

import java.math.BigInteger;
import java.util.Scanner;

``````class fctrl {

/**
* @param args
*/
public static void main(String[] args) {

Scanner sc=new Scanner(System.in);
int t;

t=sc.nextInt();
BigInteger n[] =new BigInteger[t];
for(int i=0;i<t;i++)
{
n[i]=sc.nextBigInteger();
}
BigInteger f;
BigInteger d;
int c=0;
for(int i=0;i<t;i++)
{
f=fact(n[i]);
System.out.println("fact="+f);
d=f.mod(BigInteger.valueOf(10));
f=f.divide(BigInteger.valueOf(10));
c=0;
while(d.compareTo(BigInteger.ZERO)==0)
{
c++;
d=f.mod(BigInteger.valueOf(10));
f=f.divide(BigInteger.valueOf(10));

}
System.out.println(c);
}

}

private static BigInteger fact(BigInteger l) {

//System.out.println(l);

if(l.compareTo(BigInteger.ONE)==0)
return BigInteger.valueOf(1);
else
return l.multiply(fact(l.subtract(BigInteger.valueOf(1))));

}

}
``````

i read the tutorial given for the question i understood what it said but i want to know why my program gives a wrong answer because BigInteger is big enough to handle those many long digits as i tried the factorial of hundred and it gave me the correct answer so where is the wrong answer coming from?

Why are you printing

``````System.out.println("fact="+f);
``````

?

2 Likes

extremely sorry!!!
i posted the wrong code!
will create a new question very sorry once again