一、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. POJ 1113 Wall【凸包周长】

    题目: http://poj.org/problem?id=1113 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22013#probl ...

  2. 九度OJ 1261:寻找峰值点 (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:500 解决:37 题目描述: 给定一个整数序列,该整数序列存在着这几种可能:先递增后递减.先递减后递增.全递减.全递增. 请找出那个最大值的 ...

  3. Webpack探索【1】--- 基础知识

    本文主要说明Webpack的一些基础内容.

  4. 洛谷 P2051 [SDOI2009]学校食堂

    传送门- 题目分析:首先,我们先看看做菜时间的运算机制.$(A~\texttt{or}~B)-(A~\texttt{and}~B)$这个试子看起来有点复杂(因为我太菜了),仔细想想,是不是可以转化为$ ...

  5. Cordova+FrameWork7开发简单教程

    1: 环境要有:(一个不会搭建环境的程序员,要么学,要么退出编程 ) 环境这里我只说需要什么: 1>AndroidStudio 3.0 (2.几的版本总会出问题.我喜欢用新版本) 2>co ...

  6. HackerRank - camelcase 【字符串】

    思路 找单词 第一个 单词 是小写 然后 后面的单词 第一位 都是大写 刚开始 初始化 ans = 1 然后 往后遍历 碰到 大写的 更新答案 AC代码 #include <cstdio> ...

  7. iOS 基本数据类型 和 指针 特点

    基本数据类型 : 整型int, 字符型char , 浮点型 (float 和 double), 枚举型; -- 构造类型 : 数组类型, 结构体类型, 共用体类型; -- 指针类型 : 最终要的数据类 ...

  8. DevExpress实用心得:XtraGridControl动态添加右键菜

    在使用GridControl的时候经常需要添加右键菜单. 一般的做法是自己创建菜单项,然后注册GridView的Mouse-Click事件,然后Show出定义好的菜单. 但是涉及到一些单击事件会收到编 ...

  9. 【leetcode刷题笔记】Convert Sorted List to Binary Search Tree

    Given a singly linked list where elements are sorted in ascending order, convert it to a height bala ...

  10. zookeeper学习与实战(二)集群部署

    上一篇介绍了单机版zookeeper安装,这种情况一般用于开发测试.如果是生产环境建议用分布式集群部署,防止单点故障,增加zookeeper服务的高可用. [环境介绍]       三台机器:192. ...