small fctorial problem

import java.io.;
class work
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
int []k=new int[t];
int fact;
for(int i=0;i<t;i++)
{
k[i]=Integer.parseInt(br.readLine());
}
for(int j=0;j<t;j++)
{fact=1;
while(k[j]>0)
{fact=fact
(k[j]–);
}
System.out.println(fact);
}
}
}
whats wrong with my code

Don’t use int.
Overflow will occur if you use int or long.
Use BigInteger.
Have a look at this solution-:
link

1 Like