一、Description

Larry graduated this year and finally has a job. He's making a lot of money, but somehow never seems to have enough. Larry has decided that he needs to grab hold of his financial portfolio and solve his financing problems. The
first step is to figure out what's been going on with his money. Larry has his bank account statements and wants to see how much money he has. Help Larry by writing a program to take his closing balance from each of the past twelve months and calculate his
average account balance.

Input

The input will be twelve lines. Each line will contain the closing balance of his bank account for a particular month. Each number will be positive and displayed to the penny. No dollar sign will be included.

Output

The output will be a single number, the average (mean) of the closing balances for the twelve months. It will be rounded to the nearest penny, preceded immediately by a dollar sign, and followed by the end-of-line. There will be
no other spaces or characters in the output.

这个问题实在太简单,要说有什么难的就是小弟的英语水平跟不上打字水平。由于实在太简单,我就不按老规矩分析了,只是指出需要注意的方面并拓展。

  • 听江湖传言,WA最多的就是精度问题了。不少同志由于不是用Java,所以精度没控制好。

对于这个问题,下面列出四种java里面的解决方法:

  1. 最简单的,System.out.println(String.format("%.2f", f));或者System.out,printf("%.2f",a);
  2. DecimalFormat df = new DecimalFormat("#.00");  System.out.println(df.format(f));
    1. NumberFormat nf = NumberFormat.getNumberInstance();
    2. nf.setMaximumFractionDigits(2);
    3. System.out.println(nf.format(f));
    1. BigDecimal bg = new BigDecimal(f);
    2. double f1 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
    3. System.out.println(f1);

感谢总结上面方法的同志!

版权声明:本文为博主原创文章,未经博主允许不得转载。

Poj_1004_FinancialManagement的更多相关文章

随机推荐

  1. 九度OJ 1336:液晶屏裁剪 (GCD)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:983 解决:228 题目描述: 苏州某液晶厂一直生产a * b大小规格的液晶屏幕,由于该厂的加工工艺限制,液晶屏的边长都为整数.最近由于市场 ...

  2. Python菜鸟之路:Python基础-类(1)——概念

    什么是类? 在python中,把具有相同属性和方法的对象归为一个类(class).类是对象的模板或蓝图,类是对象的抽象化,对象是类的实例化.类不代表具体的事物,而对象表示具体的事物. 类的创建 cla ...

  3. YY大厅接受不到documentcompleted事件处理

    多玩大厅在接受到了页面的documentcompleted事件,才会把遮在页面前面的YY游戏中去掉,我们的游戏页面,YY大厅接收不到事件,所以就排查了下 发现原因在于js脚本里有个用iframe做上报 ...

  4. go语言之并发编程 channel

    前面介绍了goroutine的用法,如果有多个goroutine的话相互之间是如何传递数据和通信的呢.在C语言或者JAVA中,传输的方法包括共享内存,管道,信号.而在Go语言中,有了更方便的方法,就是 ...

  5. scala与java之间的那些事

    scala与java之间的关系,我认为可以用一句话来开头:scala来源于java,但又高于java. scala的设计者Martin Odersky就是一个JAVA控,这位牛人设计了javac和编写 ...

  6. Bootstrap学习1--响应式导航栏

    备注:最新Bootstrap手册:http://www.jqhtml.com/bootstraps-syntaxhigh/index.html <nav class="navbar n ...

  7. Android Studio support 26.0.0-alpha1 Failed to resolve: com.android.support:appcompat-v7:27.+ 报错解决方法

    AS下如何生成自定义的.jks签名文件, 以及如何生成数字签名 链接:http://www.cnblogs.com/smyhvae/p/4456420.html 链接:http://blog.csdn ...

  8. 【logback】认识logback

    一. Reference:http://www.cnblogs.com/yongze103/archive/2012/05/05/2484753.html 1. Logback为取代log4j而生,l ...

  9. 第11条:用zip函数同时遍历两个迭代器

    核心知识点: (1)内置的zip函数可以平行地遍历多个迭代器. (2)python3中地zip相当于生成器,会在遍历过程中逐次产生元祖.而python2中地zip则是直接把这些元祖完全生成好,并一次性 ...

  10. php......房屋租赁练习

    多条件查询搜索页面,提交到当前页面处理 <?php include("../DB.class.php"); $db = new DB(); /*var_dump($_POST ...