HDOJ 1042 N!

 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1042

从题目可以看出最大要求1000的阶乘法,可以得知这是简单的大数阶乘

源代码:

import java.math.BigInteger;
import java.util.Scanner;

//AC 937MS 4136K 
public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int n;
		while (scanner.hasNext()) {
			n = scanner.nextInt();
			BigInteger result = new BigInteger("1");
			for (Integer i = 1; i <= n; i++) {
				String str = i.toString();
				BigInteger ii = new BigInteger(str);
				result = result.multiply(ii);
			}
			System.out.println(result);
		}
	}

}


 

你可能感兴趣的:(String,Integer,Class,import)