这道题很简单,主要是弄懂题意和注意输出:

输出的完整结果如下:

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)的更多相关文章

  1. hdoj 1753 (Java)

    刚刚开始用Java,代码难免不够简洁. import java.math.BigDecimal; import java.util.Scanner; public class Main { publi ...

  2. Spark案例分析

    一.需求:计算网页访问量前三名 import org.apache.spark.rdd.RDD import org.apache.spark.{SparkConf, SparkContext} /* ...

  3. HDOJ/HDU 2203 亲和串(简单的判断~Java的indexOf()方法秒)

    Problem Description 人随着岁数的增长是越大越聪明还是越大越笨,这是一个值得全世界科学家思考的问题,同样的问题Eddy也一直在思考,因为他在很小的时候就知道亲和串如何判断了,但是发现 ...

  4. HDOJ(HDU) 2192 MagicBuilding(用Java的Map做了下)

    Problem Description As the increase of population, the living space for people is becoming smaller a ...

  5. 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 ...

  6. hdoj 1753 大明A+B 高精度/java

    大明A+B Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  7. 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) ...

  8. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  10. HDOJ 1326. Box of Bricks 纯水题

    Box of Bricks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

随机推荐

  1. Python原型模式

    如果想根据现有对象复制出新的对象并对其修改,可以考虑原型模式(Prototype Pattern) class Point: __slots__ = ("x", "y&q ...

  2. cin、cin.get()、cin.getline()、getline()、gets()等函数的用法

    学C++的时候,这几个输入函数弄的有点迷糊:这里做个小结,为了自己复习,也希望对后来者能有所帮助,如果有差错的地方还请各位多多指教(本文所有程序均通过VC 6.0运行)转载请保留作者信息:1.cin1 ...

  3. javascript debut trick, using the throw to make a interrupt(breakpoint) in your program

    console.log('initialize'); try { throw "breakPoint"; } catch(err) {} when I debug the extj ...

  4. java 发布和逸出

    [转载]:http://www.2cto.com/kf/201310/247738.html 前言 多线程并发环境下,线程安全极为重要.往往一些问题的发生都是由于不正确的发布了对象造成了对象逸出而引起 ...

  5. java代码整理---正则表达式

    1. 邮箱验证 : package javaRegx2016311; import java.util.regex.Matcher; import java.util.regex.Pattern; p ...

  6. 《暗黑世界》安卓APK 编译流程详细说明教程!(图文)

    原地址:http://bbs.gameres.com/forum.php?mod=viewthread&tid=223671 关于开发环境的搭建,之前的相关文档已经很详细的说明,对环境的搭建请 ...

  7. Cygwin环境编译/usr/include/sys/_types.h:72:20: 致命错误:stddef.h:can not found

    环境介绍: win7_x64 +Cygwin64 gcc :4.8.2 g++:4.8.1 编译 c++的helloworld.cpp 一直失败! 代码如下: #include <iostrea ...

  8. 获取保存在沙盒中plist文件的用户的字典信息

    获取保存在沙盒中plist文件的用户的字典信息

  9. *[topcoder]AstronomicalRecords

    http://community.topcoder.com/stat?c=problem_statement&pm=12804&rd=15706 首先A和B的长度都不一定一样,里面的元 ...

  10. SPRING IN ACTION 第4版笔记-第三章ADVANCING WIRING-009-用SPEL给bean运行时注入依赖值

    1.When injecting properties and constructor arguments on beans that are created via component-scanni ...