大数 N!——java
2015-09-25 20:34
274 查看
n 的 阶 乘
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
Sample Output
言简意赅,即求n的阶乘。
附java代码,记之。
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
言简意赅,即求n的阶乘。
附java代码,记之。
import java.util.*; import java.math.*; public class Main{ public static void main(String[] args){ Scanner cin=new Scanner(System.in); int a; while(cin.hasNextInt()){ a=cin.nextInt(); BigInteger b=BigInteger.ONE; for(BigInteger i=BigInteger.ONE; i.compareTo(BigInteger.valueOf(a))!=1; i=i.add(BigInteger.ONE)){ b=b.multiply(i); } System.out.println(b); } cin.close(); } }
相关文章推荐
- 如何用Netbeans加背景图片
- Thinking In Java读书笔记--对象导论
- java Scanner类的几点注意事项
- Java核心技术第3章(2)
- 【Java高级】Java中NIO非阻塞socket通信
- Spring事务处理时自我调用的解决方案及一些实现方式的风险
- java程序——从命令行接收多个数字,求和之后输出结果
- java设计界面与按钮之间的连接方法
- java Timer和TimerTask使用
- test7.15
- java构造函数
- Java中随机数生成的两种方法,以及math的floor
- test7.14
- javaweb用户密码的封装
- Java基础知识强化96:Calendar类之获取任意年份的2月有多少天的案例
- Java虚拟机5:Java垃圾回收(GC)机制详解
- Java学习目录(初级篇)
- eclipse汉化
- Java基础知识强化95:Calendar类之Calendar类的add()和set()方法
- Java面向对象之内部类