Java求大整数的阶乘代码
代码转自:http://blog.sina.com.cn/s/blog_64ca6cfb0100u1aq.html
import java.io.*; public class jiecheng { public static void main(String args[]) throws IOException{ int Data[]=new int[80]; int Digit; int i,j,r,k; int N; for(i=1;i<40;i++) Data[i]=0; Data[0]=1; Data[1]=1; Digit=1; System.out.println("Enter a number what you want to calculus:"); BufferedReader dr=new BufferedReader(new InputStreamReader(System.in)); N=Integer.parseInt(dr.readLine()); for(i=1;i<N+1;i++) { for(j=1;j<Digit+1;j++) { Data[j]*=i; } for(j=1;j<Digit+1;j++) { if(Data[j]>10) { for(r=1;r<Digit+1;r++) { if(Data[Digit]>10) { Digit++; } Data[r+1]+=Data[r]/10; Data[r]=Data[r]; } } } System.out.print(i+"!= "); for(k=Digit;k>0;k--) { System.out.print(Data[k]); } System.out.println(""); } } }