标签:stat static [] 问题 span util 逆序数 for 精确
import java.util.Arrays; import java.util.Scanner;
/**
* 阶乘的精确值
* @author NEU-2015
*
*/ public class Demo { public static void main(String[] args) { Scanner input = new Scanner(System.in); int x; int[] array = new int[3000]; //逆序数组 int s; int c; //进位进了多少 boolean flag; while(input.hasNext()) { x = input.nextInt(); Arrays.fill(array, 0); array[0] = 1; //设置初始值 for(int i = 2; i <= x; i++) { c = 0; for(int j = 0; j < 3000; j++) { s = array[j] * i + c; array[j] = s % 10; c = s/10; } } flag = true; for(int j = 3000-1; j >= 0; j--) { if(!(array[j] == 0) && flag) { //除去高位第一个非零数前的0 eg: 123000 因为是逆序 所以输出321 flag = false; } if(!flag) { System.out.print(array[j]); } } System.out.println(); } } }
标签:stat static [] 问题 span util 逆序数 for 精确
原文地址:http://www.cnblogs.com/NEU-2015/p/7502763.html