每天一道算法_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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • SSH+activity工作流集成开发「建议收藏」

    SSH+activity工作流集成开发「建议收藏」一直没有更新最近,把以前的资料整理下。SSH的集成配置清查看上一篇struts-2.3.24+spring-framework-4.1.6.RELEASE+hibernate-release-4.3.10.Final集成开发导入activity工作流需要的jaractiviti-bpmn-converter-5.16.4.jaractiviti-bpmn-layout-5

    2022年5月18日
    41
  • C# 验证码

    C# 验证码

    2022年3月12日
    46
  • java获取当前年月日时间戳_现在的年月日怎么来的

    java获取当前年月日时间戳_现在的年月日怎么来的两种方法,通过Date类或者通过Calendar类。Date类比较简单,但是要得到细致的字段的话Calendar类比较方便。importjava.text.DateFormat;importjava.text.SimpleDateFormat;importjava.util.Calendar;importjava.util.Date;importjava.util.L

    2025年9月21日
    6
  • ADB常用命令及其用法大全「建议收藏」

    ADB常用命令及其用法大全「建议收藏」前言:本文主要记述ADB的常用命令,关于ADB用法大全,可参考文末链接ADB简介:ADB,即AndroidDebugBridge,它是Android开发/测试人员不可替代的强大工具,也是Android设备玩家的好玩具。安卓调试桥(AndroidDebugBridge,adb),是一种可以用来操作手机设备或模拟器的命令行工具。它存在于sdk/platform-to…

    2022年4月30日
    53
  • idea tomcat catalina log乱码_xshell查看日志乱码怎么解决

    idea tomcat catalina log乱码_xshell查看日志乱码怎么解决以前一直使用Eclipse,现在试用IDEA,遇到一些坑,通过网上的答案基本都解决了,但有些答案不好,比如这个问题。1、原因分析Tomcat运行JavaWeb的程序,在IDEA控制台中输出显示,我们一般都是用UTF8编码。从Java源码到IDEA控制台,大致分为几个阶段:1)源码:即*.java原文件,是纯文本文件。编码方式在IDEA的Settings>Editor>FileEncodings中设置;2)…

    2022年9月26日
    2
  • STM32的优先级NVIC_PriorityGroupConfig的理解及其使用[通俗易懂]

    STM32的优先级NVIC_PriorityGroupConfig的理解及其使用[通俗易懂]写作原由:因为之前有对stm32优先级做过研究,但是没时间把整理的东西发表,最近项目需要2个串口,但是不是两个串口同时使用,只是随机使用其中一个,程序对2个串口的优先级需要配置;此文思路:“中断优先级”思维导图–&gt;关键要点—&gt;结合图和要点相关程序应用例程讲解;我们先来看ST公司的一张图:我自己依据此图理解,应用思维导图画了一张方便理解:(如果看不清可通过ctrl+鼠标滑轮   …

    2022年5月28日
    40

发表回复

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

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