java在查找大于12的数字的阶乘时得到错误的输出
我试图用Java解决codechef中提供的一个factorial problem。下面是我的代码,我试过了,得到了12个数字的结果。13天!,我得到了错误的答案。对于较大的数字,我得到零输出。我正处于学习阶段,请帮助我
import java.util.Scanner;
public class Factorial {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner dd = new Scanner(System.in);
int a=dd.nextInt();
long fact[]=new long[a];
for (int i=0;i<a;i++)
{
int b = dd.nextInt();
int factorial=0,d=0;
if(b==0) System.out.println(1);
for(int temp=b-1;temp>1;temp=d-1)
{
d=temp;
b=b*temp;
}
fact[i]=b;
}
for(int j=0;j<a;j++)
{
System.out.println(fact[j]);
}
}
}
# 1 楼答案
十三!!大于最大整数值,并且是在整数上计算的