-2
问题是这样的 - 银行每月支付曼尼什利息。 Manish也是一个坚定的投资者,并且避免从这个账户中撤回任何东西,因为他现在相信复利的力量。鉴于投资语料库,固定年利率和到期期限计算了马尼什在任期结束时最终节省的金额。这些约束给出:复利计划
P > 0 ; it can be float value, where p is investment corpus
R >=0 ; it can be float value, where r is rate of interest per annum
T >0 ; it can be integer only, where t is tenure(given in months)
Calculation should be done upto 11-digit precision.
我的代码是这样的:
import java.io.*;
import java.util.*;
public class CompoundInterest
{
public static void main(String args[])
{
float principal;
int months;
float rate;
double final_amount = 0;
Scanner sc = new Scanner(System.in);
System.out.println("Principal: \n");
principal = sc.nextFloat();
System.out.println("Months: \n");
months = sc.nextInt();
System.out.println("Interest rate: \n");
rate = sc.nextFloat();
for(int x = 1;x<=months;x++)
{
double amount = principal*Math.pow(1+rate,x);
final_amount = final_amount+amount;
}
System.out.println("final_amount"+final_amount);
}
}
如果我给输入为25,4和6分别..输出应为152 我得到输出任何人都可以帮我纠正我的这个程序并运行这个程序吗?
它是你的任务吗? – Rustam
你的公式看起来不正确。见[这里](http://www.calculatorsoup.com/calculators/financial/compound-interest-calculator.php) – SMA
你可以问你的老师,如何计算float值可能达到11位精度。 –