**Let’s say an amount of $2,000 is deposited into a bank account as a fixed deposit at an annual interest rate of 8%, compounded monthly, the compound interest after 5 years would be:**

P = 2000.

R = 8/100 = 0.08 (decimal).

n = 12.

t = 5.

Let’s put these values into the formula.

**Compound Interest** = 2000 (1 + 0.08 / 12) (12 * 5) – 2000 = $979.69

So, the compound interest after 5 years is $979.69.

```
public class JavaExample {
public void calculate(int p, int t, double r, int n) {
double amount = p * Math.pow(1 + (r / n), n * t);
double cinterest = amount - p;
System.out.println("Compound Interest after " + t + " years: "+cinterest);
System.out.println("Amount after " + t + " years: "+amount);
}
public static void main(String args[]) {
JavaExample obj = new JavaExample();
obj.calculate(2000, 5, .08, 12);
}
}
```

Output:

```
Compound Interest after 5 years: 979.6914166032102
Amount after 5 years: 2979.69141660321
```