每天一道算法_5_Financial Management「建议收藏」

今天的题目更简单,在考虑是不是应该有挑选性的选题目做。题目是Financial Management,如下: DescriptionLarry graduated this year and finally has a job. He’s making a lot of money, but somehow never seems to have enough. Larry has

大家好,又见面了,我是全栈君。

今天的题目没法更简单了,在考虑是不是应该有挑选性的选题目做。

题目是Financial Management,如下:

 

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.

Sample Input

100.00
489.12
12454.12
1234.10
823.05
109.20
5.27
1542.25
839.18
83.99
1295.01
1.75

Sample Output

$1581.42

 

代码如下:

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class FinancialManagement {
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		List<Float> list = new ArrayList<Float>();
		int all = 12;
		while(all > 0){
			float f = Float.valueOf(in.nextLine());
			list.add(f);
			all --;
		}
		float sum = 0;
		for(int i = 0; i < list.size(); i ++){
			sum += list.get(i);
		}
		float average = sum/12;
		BigDecimal b = new BigDecimal(average);
		average = b.setScale(2, BigDecimal.ROUND_HALF_UP).floatValue();
		System.out.println("$"+average);
	}
}

 

作者:jason0539

微博:http://weibo.com/2553717707

博客:http://blog.csdn.net/jason0539(转载请说明出处)

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/121385.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 关于OATUH中的AUTHRAZITON CODE和TOKEN的关系,实际上就是这么回事

    关于OATUH中的AUTHRAZITON CODE和TOKEN的关系,实际上就是这么回事

    2021年9月12日
    49
  • python 拼接字符串字作为字符串使用(python连接字符串)

    Python字符串拼接数字的方法发布时间:2020-08-0515:40:44来源:亿速云阅读:99作者:小新这篇文章将为大家详细讲解有关Python字符串拼接数字的方法,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。Python字符串拼接数字在某些特殊场景中,我们需要将字符串与数字进行拼接,而Python不允许直接拼接数字和字符串,程序必须先将数字转换成字…

    2022年4月12日
    93
  • 树莓派开发环境搭建(树莓派5)

    在本系列文章的第一部分中,我们将在一台树莓派Pi3ModelB上安装并运行一个以太坊区块链客户端。毫无疑问,区块链绝对是当前的热点。之所以会这样,很大程度上是因为比特币以及其他加密货币让很多人一夜暴富。但是,区块链的应用并不仅限于加密货币领域,考虑到其去中心化以及防篡改等特性,区块链技术还可以用到IoT应用中。因此,除了加密货币和安全交易之外,以太坊平台还可以提供一种分布式的计算平台。在这篇…

    2022年4月12日
    177
  • python中for循环的用法-Python for循环及基础用法详解

    python中for循环的用法-Python for循环及基础用法详解Python中的循环语句有2种,分别是while循环和for循环,前面章节已经对while做了详细的讲解,本节给大家介绍for循环,它常用于遍历字符串、列表、元组、字典、集合等序列类型,逐个获取序列中的各个元素。for循环的语法格式如下:for迭代变量in字符串|列表|元组|字典|集合:代码块格式中,迭代变量用于存放从序列类型变量中读取出来的元素,所以一般不会在循环中…

    2022年8月12日
    18
  • 解决iframe参数过长无法加载问题小记

    解决iframe参数过长无法加载问题小记项目中用到了iframe,传参的时候使用的src属性,默认采用的get方式,此种方式在参数较长的时候就会报错(404无法找到资源),为了解决这种情况,改为采用post方式提交。解决方法:结合form表单,利用表单的post请求方式达到目的。实现方式 增加一个form表单的标签,method设置为post,target设置一个标识,假如target=”target1” 在iframe设置na…

    2022年7月12日
    34
  • grid常用设置

    grid常用设置父元素1.dispaly:grid|inline-grid|subgrid;grid:生成块级网格inline-grid:生成行内网格subgrid:如果网格容器本身是网格项(嵌套网格容器),此属性用来继承其父网格容器的列、行大小2.grid-template-columns行大小grid-template-rows列大小3.单元格间距grid-column-…

    2022年7月27日
    10

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号