【问题标题】:compound interest after 1, 3 and 5 years1、3和5年后的复利
【发布时间】:2014-02-18 02:06:11
【问题描述】:

我有计算复利的代码,但我需要它在 1、3 和 5 年后执行此操作。我试过了,但似乎无法让它工作。谁能帮帮我?

import java.util.Scanner; 

public class CompoundInterest { 

public static void main(String[] args) { 
Scanner input = new Scanner(System.in); 

double principal = 0; 
double rate = 0; 
double time = 0; 

double x = 0; 

System.out.print("Enter the amount invested : "); 
principal = input.nextDouble(); 

System.out.print("Enter the Rate of interest : "); 
rate = input.nextDouble(); 

System.out.print("Enter the Time of loan : "); 
time = input.nextDouble(); 


x = principal * Math.pow((1 + rate/12),time); 
 x = Math.pow(5,3);

System.out.println(""); 
System.out.println("The Compound Interest after 1 year is : " 
+ x); 

} 

} 

【问题讨论】:

标签: java math calculator rate


【解决方案1】:

为什么要把x设置成principal *((1+r/12),time),然后设置x=math.pow(5,3)

x 现在设置为math.pow(5,3),与您输入的本金、费率和时间无关。

此外,您应该指定时间输入是年,因为您在费率问题中已经硬编码。

【讨论】:

  • 不,不,这需要几个月,而不是几年,才能奏效;但 +1 以获得正确答案。
猜你喜欢
  • 2020-07-19
  • 2011-08-11
  • 2021-09-05
  • 1970-01-01
  • 2016-06-20
  • 2021-09-09
  • 1970-01-01
  • 2016-11-27
  • 1970-01-01
相关资源
最近更新 更多