一、Description

A simple mathematical formula for e is

e=Σ0<=i<=n1/i!


where n is allowed to go to infinity. This can actually yield very accurate approximations of e using relatively small values of n.

Input

No input

Output

Output the approximations of e generated by the above formula for the values of n from 0 to 9. The beginning of your output should appear similar to that shown below.



二、题解

        注意精度的控制,结果控制在9位小数,String .format("%.9f",sum)。

三、java代码

public class Main {

    public static void main(String[] args) {
int i,j,fac;
double sum=2.5d;
System.out.println("n "+"e");
System.out.println("- "+"-----------");
System.out.println("0 "+"1");
System.out.println("1 "+"2");
System.out.println("2 "+"2.5");
for(i=3;i<10;i++){
fac=1;
for(j=1;j<=i;j++){
fac*=j;
}
sum+=1.0 /(fac);
System.out.print(i+" ");
System.out.println(String .format("%.9f",sum));
}
}
}

poj 1517 u Calculate e(精度控制+水题)的更多相关文章

  1. Poj 2350 Above Average(精度控制)

    一.Description It is said that 90% of frosh expect to be above average in their class. You are to pro ...

  2. OpenJudge/Poj 1517 u Calculate e

    1.链接地址: http://bailian.openjudge.cn/practice/1517 http://poj.org/problem?id=1517 2.题目: 总时间限制: 1000ms ...

  3. poj 1517 u Calculate e

    u Calculate e Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19465   Accepted: 11362   ...

  4. POJ 3254 - Corn Fields - [状压DP水题]

    题目链接:http://poj.org/problem?id=3254 Time Limit: 2000MS Memory Limit: 65536K Description Farmer John ...

  5. POJ 3369 Meteor Shower (BFS,水题)

    题意:给定 n 个炸弹的坐标和爆炸时间,问你能不能逃出去.如果能输出最短时间. 析:其实这个题并不难,只是当时没读懂,后来读懂后,很容易就AC了. 主要思路是这样的,先标记所有的炸弹的位置,和时间,在 ...

  6. poj 1979 Red and Black(dfs水题)

    Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...

  7. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  8. [POJ 1000] A+B Problem 经典水题 C++解题报告 JAVA解题报告

        A+B Problem Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 311263   Accepted: 1713 ...

  9. poj 1004:Financial Management(水题,求平均数)

    Financial Management Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 126087   Accepted: ...

随机推荐

  1. SQLServer判断一个IP是否在一个IP段里

    declare @ip1 varchar(20)declare @ip2 varchar(20)set @ip1='221.231.138.101'set @ip2='255.255.255.255' ...

  2. Difference Between ZIP and GZIP

    From: http://www.differencebetween.net/technology/difference-between-zip-and-gzip/ Summary: 1. GZIP ...

  3. JDK动态代理连接池

    JDK动态代理   1 什么是JDK动态代理 刚刚写ItcastConnection时爽么?因为Connection中的方法太多了,每个都要写,所以很累吧.累点到是没什么,可以完成功能就是好的.但是不 ...

  4. spring 3.2 后 annotation-driven 注册新的类

    DefaultAnnotationHandlerMapping 和 AnnotationMethodHandlerAdapter 的使用已经过时! DefaultAnnotationHandlerMa ...

  5. R中常用数据挖掘算法包

    数据挖掘主要分为4类,即预测.分类.聚类和关联,根据不同的挖掘目的选择相应的算法.下面对R语言中常用的数据挖掘包做一个汇总: 连续因变量的预测: stats包 lm函数,实现多元线性回归 stats包 ...

  6. python调用java jython

    环境:openjdk8,python2.7,jython2.7jython下载地址     http://www.jython.org/downloads.html 下载完成后,运行下面命令 java ...

  7. Elipse 快捷键

    1. eclipse里面如何快速收缩当前类文件里面的所有方法和注释收缩:ctrl+shift+/展开:ctrl+shift+*注意:这个/和*要是数字键盘上的/和*.   2. shift+enter ...

  8. linux共享库加载

    参考自: <<程序员的自我修养--链接.装载与库>> 第八章 Linux共享库的组织 以下截取部分内容 (这本书比较好的讲解了从程序的链接,装载,到运行) 共享库的兼容性 li ...

  9. java深入探究07-jdbc上

    1.连接数据库三种方式 //连接数据库的URL private String url = "jdbc:mysql://localhost:3306/day17"; // jdbc协 ...

  10. JAVA- 数据库连接池原理

    第一次Java程序要在MySQL中执行一条语句,那么就必须建立一个Connection对象,代表了与MySQL数据库的连接通过直接发送你要执行的SQL语句之后,就会调用Connection.close ...