Java 对复利算法的混淆

Confusion on compound interest arithmetic with Java

我希望这不是一个非常明显的问题,但我是 Java 的新手并且我一直在创建一个复利计算器。我不想获取用户输入的所有值并计算它们。

P = present value,
r = rate,
m = times compounded in a year,
t = years compounded. 
A = the amount at the end of the term

A 正是我要找的。复利的公式是

A = P(1+r/m)^mt.

    A = Math.pow((P*(1+r/m)),m*t);
    System.out.println("The amount(A) equals "+A);

我觉得我可能知道为什么计算不正确,但我不知道正确的方法。

这应该可以解决您的问题

double amount,Principal ;
int r,m,t;
Amount = Principal * Math.pow( (1+(r/m)) , m*t );
System.out.println("The amount(A) equals "+amount);

我认为你的公式不正确。你需要这样写:

public static void main(String[] args) {
        int p = 100;
        int t = 5;
        int r = 10;
        int m = 2;
        double amount = p * Math.pow(1 + (r / m), m * t);
        double interest = amount - p;
        System.out.println("Compond Interest is " + interest);
        System.out.println("Amount is " + amount);

    }