Calculate Compound Interest in Java

Calculate Compound Interest in Java

Here you will get the example code to Calculate Compound Interest in Java programming.

Calculate Compound Interest Formula

Amt = P(1 + r/n)^(nt)

Where:

Amt is final amount(principal + interest).
P is the principal amount
r is rate of interest (yearly).
n is the annual number of times interest is compounded.
t is time in years.

Example:
Suppose you invest rupees 1,000 (P) in a savings account with an annual interest rate of 5% (r). The interest is compounded annually (n = 1), and you plan to leave the money in the account for 3 years (t).

Using the compound interest formula:

Amt = P(1 + r/n)^(nt)

Amt = 1,000(1 + 0.05/1)^(1*3)

Amt = 1,000(1 + 0.05)^3

Amt = 1,000(1.05)^3

Amt = 1,000(1.157625)

Amt = 1,157.63

So, after 3 years of investing rupees 1,000 in a savings account with a 5% annual interest rate. You would have approximately rupees 1,157.63 in your account.

Program to Calculate Compound Interest in Java

Output

C:\CodeRevise\java>javac CIcalc.java

C:\CodeRevise\java>java CIcalc
Enter principal amount: 1000
Enter annual interest rate (in decimal form): 0.05
Enter the number of times interest is compounded per year: 1
Enter number of years: 3
The final amount after 3 years will be: 1157.6250000000002

 

 

 

Check out our other Java Programming Examples

 

 

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top