HDOJ-ACM1012(JAVA)

这道题很简单,主要是弄懂题意和注意输出:
输出的完整结果如下:
n e
- -----------
0 1
1 2
2 2.5
3 2.666666667
4 2.708333333
5 2.716666667
6 2.718055556
7 2.718253968
8 2.718278770
9 2.718281526
java代码如下:
import java.util.*;
import java.io.*; public class Main{ public static void main(String[] arg){
Scanner scan = new Scanner(new BufferedInputStream(System.in));
System.out.println("n e");
System.out.println("- -----------");
for(int i =0 ; i != 10 ; i ++){
if(i<2){
System.out.println(i + " " + (int)getE(i));
}else if(i<3){
System.out.println(i + " " +getE(i));
}else{
System.out.printf("%d %.9f",i,getE(i));
System.out.println();
}
}
scan.close();
} static double getE(int from){
double e = 0;
if(from == 0){
e=1;
}else{
while(from!=0){
e = e + 1.0/getProduct(from);
from--;
}
e +=1;
}
return e;
} static int getProduct(int from){
int p=1;
while(from != 0){
p*=from;
from--;
}
return p;
}
}
HDOJ-ACM1012(JAVA)的更多相关文章
- hdoj 1753 (Java)
刚刚开始用Java,代码难免不够简洁. import java.math.BigDecimal; import java.util.Scanner; public class Main { publi ...
- Spark案例分析
一.需求:计算网页访问量前三名 import org.apache.spark.rdd.RDD import org.apache.spark.{SparkConf, SparkContext} /* ...
- HDOJ/HDU 2203 亲和串(简单的判断~Java的indexOf()方法秒)
Problem Description 人随着岁数的增长是越大越聪明还是越大越笨,这是一个值得全世界科学家思考的问题,同样的问题Eddy也一直在思考,因为他在很小的时候就知道亲和串如何判断了,但是发现 ...
- HDOJ(HDU) 2192 MagicBuilding(用Java的Map做了下)
Problem Description As the increase of population, the living space for people is becoming smaller a ...
- HDOJ(HDU) 2133 What day is it(认识下Java的Calendar类---日期类)
Problem Description Today is Saturday, 17th Nov,2007. Now, if i tell you a date, can you tell me wha ...
- hdoj 1753 大明A+B 高精度/java
大明A+B Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- hdoj 1002 A + B Problem II 高精度 java
A + B Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序
FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- HDOJ 1326. Box of Bricks 纯水题
Box of Bricks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
随机推荐
- Stop a hung service 关闭一个无响应的windows 服务
If you ever have trouble with a service being stuck in a 'starting' or 'stopping' state, you can run ...
- 【BZOJ】1925: [Sdoi2010]地精部落 DP+滚动数组
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1925 题意:输入一个数N(1 <= N <= 4200),问将这些数排列成折线 ...
- 导航栏 & 状态栏覆盖
当 automaticallyAdjustsScrollViewInsets 为 YES 时,也是默认行为,表现就比较正常了,和 edgesForExtendedLayout = UIRectEdge ...
- cxlibw-5-0.dll was not found
However every once in a while we are getting the following error message: "This application has ...
- C# zip/unzip with ICSharpCode.SharpZipLib
download ICSharpCode and add reference using System; using System.Collections.Generic; using System. ...
- <四> SQL存储过程
存储过程的定义: create procedure procedurename @param1 nvarchar(30) as select * from tablename where name = ...
- appcache checking update
<!DOCTYPE html> <html manifest="a.appcache"> <head> <title></ti ...
- SWFUpload 中文乱码问题
解决办法:两种: 第一种:把handlers.js的编码方式改为UTF-8(用记事本打开,选择编码格式为utr-8即可) 第二种:在有swfupload控件页面的page_load种加: Respon ...
- mysql数据库乱码
问题:mysql数据库的编码都设置为utf8的情况下,用jdbc往数据库中插入数据时仍然乱码, 解决方法:在jdbc的中加上参数characterEncoding=utf8&useUnicod ...
- 转 scrollLeft,scrollWidth,clientWidth,offsetWidth之完全详解
scrollHeight: 获取对象的滚动高度. scrollLeft:设置或获取位于对象左边界和窗口中目前可见内容的最左端之间的距离 scrollTop:设置或获取位于对象最顶端和窗口中可见内容的最 ...