当前位置: 首页 > news >正文

每天一道算法_5_Financial Management

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

题目是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(转载请说明出处)

相关文章:

  • Android生命周期
  • 九度oj 1545奇怪的连通图
  • android中类似 QQ震动窗口的实现,带声音和振动效果
  • Linux下多任务间通信和同步-概述
  • 一初探js特效魅力之全选不选反选04
  • 360全线产品从小米应用商店下架
  • 阿里IPO弃港赴美?
  • 浅析数据库设计三范式
  • linux enable命令学习
  • Linux操作系统以及各大发行版介绍——Linux operating system and major distribution is introduced...
  • 一初探js特效魅力之选项卡05
  • 一初探js特效魅力之数组06
  • 大根堆排序
  • 初探js特效魅力之定时器的使用one
  • 初探js特效魅力之延时提示框07
  • “大数据应用场景”之隔壁老王(连载四)
  • 【剑指offer】让抽象问题具体化
  • Android开源项目规范总结
  • el-input获取焦点 input输入框为空时高亮 el-input值非法时
  • js对象的深浅拷贝
  • JS函数式编程 数组部分风格 ES6版
  • php ci框架整合银盛支付
  • TCP拥塞控制
  • 关于Java中分层中遇到的一些问题
  • ------- 计算机网络基础
  • 前端性能优化——回流与重绘
  • 前端自动化解决方案
  • 思否第一天
  • Android开发者必备:推荐一款助力开发的开源APP
  • hi-nginx-1.3.4编译安装
  • #每日一题合集#牛客JZ23-JZ33
  • (3)STL算法之搜索
  • (javascript)再说document.body.scrollTop的使用问题
  • (Redis使用系列) Springboot 使用redis实现接口Api限流 十
  • (附源码)php投票系统 毕业设计 121500
  • (附源码)springboot学生选课系统 毕业设计 612555
  • (免费领源码)python#django#mysql校园校园宿舍管理系统84831-计算机毕业设计项目选题推荐
  • .md即markdown文件的基本常用编写语法
  • .Net Core webapi RestFul 统一接口数据返回格式
  • .NET Core实战项目之CMS 第十二章 开发篇-Dapper封装CURD及仓储代码生成器实现
  • .NET 跨平台图形库 SkiaSharp 基础应用
  • .NET/ASP.NETMVC 深入剖析 Model元数据、HtmlHelper、自定义模板、模板的装饰者模式(二)...
  • .NET/MSBuild 中的发布路径在哪里呢?如何在扩展编译的时候修改发布路径中的文件呢?
  • .NET6使用MiniExcel根据数据源横向导出头部标题及数据
  • .net访问oracle数据库性能问题
  • .NET高级面试指南专题十一【 设计模式介绍,为什么要用设计模式】
  • .net和php怎么连接,php和apache之间如何连接
  • .Net转Java自学之路—基础巩固篇十三(集合)
  • [ Linux Audio 篇 ] 音频开发入门基础知识
  • [100天算法】-x 的平方根(day 61)
  • [2008][note]腔内级联拉曼发射的,二极管泵浦多频调Q laser——
  • [android]-如何在向服务器发送request时附加已保存的cookie数据
  • [AutoSar NVM] 存储架构
  • [C#]猫叫人醒老鼠跑 C#的委托及事件
  • [C]编译和预处理详解