【HDU】1042 - N!(java - BigDecimal)
2016-07-28 09:07
183 查看
点击打开题目
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 74697 Accepted Submission(s): 21717
Problem Description
Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!
Input
One N in one line, process to the end of file.
Output
For each N, output N! in one line.
Sample Input
1
2
3
Sample Output
1
2
6
Author
JGShining(极光炫影)
用java算大数真的很方便啊!
代码如下:
import java.math.BigDecimal;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
while (sc.hasNext())
{
int n = sc.nextInt();
BigDecimal ans=new BigDecimal(1);
for (int i = 2 ; i <= n ; i++)
{
BigDecimal t = new BigDecimal(i);
ans = ans.multiply(t);
}
System.out.println(ans);
}
}
}
N!
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 74697 Accepted Submission(s): 21717
Problem Description
Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!
Input
One N in one line, process to the end of file.
Output
For each N, output N! in one line.
Sample Input
1
2
3
Sample Output
1
2
6
Author
JGShining(极光炫影)
用java算大数真的很方便啊!
代码如下:
import java.math.BigDecimal;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
while (sc.hasNext())
{
int n = sc.nextInt();
BigDecimal ans=new BigDecimal(1);
for (int i = 2 ; i <= n ; i++)
{
BigDecimal t = new BigDecimal(i);
ans = ans.multiply(t);
}
System.out.println(ans);
}
}
}
相关文章推荐
- JAVA-GetDay
- #500-5 集合框架 (初识)
- Spring4----Bean之间的关系
- 我的文章:开源组件
- 简单介绍java Enumeration
- Java对文件的读、写随机访问,RandomAccessFile类的使用分析
- SpringBootHowTo 有许多spring boot下的常用问题及解答列表
- 我的文章:Filter
- Java Mysql Hive操作
- Java引用类型
- Java开发必装的IntelliJ IDEA插件
- shiro-springmvc-mybatis登录认证 权限控制
- Spring事务传播简介
- java知识容易混淆的知识点总结
- 我的文章:Servlet、Session、Cookie
- struts2中获取web资源小结
- Java NIO 系列教程
- java 操作cookie
- 我的文章:XML
- Java_编程实例_需求四