I have been making a program to find the number of trailing zeroes at the end of the factorial of a number.
The program first of all takes the input ‘a’- the number of the numbers it has to operate on. Then it takes ‘a’ number of inputs and calculates number of zeroes at the end of the factorial of the integers I have inserted. The problem lies in the 6th line , where I have declared a variable of type int. This variable stores the integer quotient of a division process. But the compiler keeps reporting the error "Possible lossy conversion from double to int. Now on declaring the variable of type double, the variable stops ignoring the fractional part of the number produced after division. How can I rectify it?
The code I have written is as follows :
Scanner p=new Scanner(System.in);
int a=p.nextInt(); //This shows the numbers of inputs to be taken
for(int i=1;i<=a;i++) //This loops makes program takes a number of inputs
{
int b=p.nextInt();
int sum=0; //This line is the one creating problem.
for(int j=1;Math.pow(5,j)<=b;j++) //Taking out max power of 5 contained in the input.
{
sum=sum+b/Math.pow(5,j); //This is where it reports the lossy conversion error
}
System.out.println(sum);
}