一、Description

Farmer John made a profit last year! He would like to invest it well but wonders how much money he will make. He knows the interest rate R (an integer between 0 and 20) that is compounded annually at his bank. He has an integer
amount of money M in the range 100..1,000,000. He knows how many years Y (range: 0..400) he intends to invest the money in the bank. Help him learn how much money he will have in the future by compounding the interest for each year he saves. Print an integer
answer without rounding. Answers for the test data are guaranteed to fit into a signed 32 bit integer.

Input

* Line 1: Three space-separated integers: R, M, and Y

Output

* Line 1: A single integer that is the number of dollars FJ will have after Y years.

二、题解

       题目的提示很明显,计算过程如下:

 INPUT DETAILS:

      5% annual interest, 5000 money, 4 years

OUTPUT DETAILS:

Year 1: 1.05 * 5000 = 5250

Year 2: 1.05 * 5250 = 5512.5

Year 3: 1.05 * 5512.50 = 5788.125

Year 4: 1.05 * 5788.125 = 6077.53125

The integer part of 6077.53125 is 6077.

     需要注意的是计算过程中间结果要用double存放。

三、java代码

import java.util.Scanner;

  public class Main {

	  public static void main(String[] args)  {
Scanner sc = new Scanner(System.in);
int r,m,y,i;
double result,r1;
r=sc.nextInt();
m=sc.nextInt();
y=sc.nextInt();
r1=0.01 * r+1;
result=m;
for(i=0;i<y;i++){
result*=r1;
}
System.out.println((int)result);
}
}

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

最新文章

  1. iOS10之Expected App Behaviors
  2. [Java入门笔记] 面向对象编程基础(三):成员变量和局部变量
  3. nginx入门篇----负载均衡策略
  4. TypeScript实例
  5. 最近这么火的iOS视频直播
  6. CSU 1120 病毒(DP)
  7. nullcon HackIM 2016 -- Programming Question 1
  8. Leetcode: Evaluate Division
  9. 使用 Windows 窗体 TextBox 控件创建密码文本框
  10. 从Android Handler内部类到WeakReference的知识关联
  11. LigerUI权限系统之菜单管理
  12. hdu 3247 AC自动+状压dp+bfs处理
  13. faker模块
  14. python 实践项目 强密码检测
  15. Docker 搭建 ELK 收集并展示 tomcat 日志
  16. 【PAT】B1079 延迟的回文数(20 分)
  17. CRM项目之stark组件(1)
  18. 【LeetCode每天一题】Multiply Strings(字符串乘法)
  19. springboot 错误处理
  20. while 语句

热门文章

  1. 九度OJ 1344:可乐瓶展览 (DP)
  2. 6.2.3-AbstractBeanFactory
  3. APNS推送原理详解
  4. 【python】-- RabbitMQ RPC模型
  5. 上传项目至GitHub
  6. iOS 发大招 otherButtonTitles:(nullable NSString *)otherButtonTitles, ... 写法 &amp;&amp; 编写通用类的时候关于可变参数的处理
  7. 【leetcode刷题笔记】Subsets II
  8. P3506 [POI2010]MOT-Monotonicity 2
  9. python正则-- re模块
  10. hbase shell概述