## Java Program to Calculate Compound Interest Hey Guys! If you want to know the topic about Java Program to Calculate Compound Interest then read this tutorial. Yes, I’m going to teach about compound interests and how to perform a task using the java program? here. Let’s start the tutorial.

Contents

## Compound Interest

Compound interest is the interest calculated on the principal and the interest accumulated over the previous period. It simply means the interest on interests. It is mostly used in the banking and financial sectors to earn interest.

The formula for calculating the compound interest will provide below:

``P (1 + R/n) (nt) - P``

As usual, “P” is a principal amount, “R” is a rate of interest, “t” is the number of years, and “N” is the number of compounding periods.

## Java Program to Calculate Compound Interest

This is the example program to do a task here.

``````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(700000, 15, .14, 12);
}
}``````

## Explanation

In this program, We will calculate both compound interest and the amount after a particular number of years. After running this program, The program asks you to enter all parameters based on the formula.

The values of the compound interest and the amount after a particular number of years will be calculated based on the applying values into the formula along with the Math.pow() function.

Finally, The output will be displayed on the screen using the system.out.printIn() function.

`Read Also : Java Program to Calculate Simple Interest`

## Note

You can also calculate compound interest using PHP as well as calculate compound interest in python. Please read those articles if you want to learn.

## Output

Below, You will see the example output of the java program to calculate compound interest. The input parameters will be either your wish or a user’s choice.

``````Compound Interest after 15 years: 4947254.556538412
Amount after 15 years: 5647254.556538412``````

## Final Thoughts

I hope this article helps you to learn Java Program to Calculate Compound Interest. If you face any issues please let me know via the comment section. Share this article with other Java program developers via social networks. Thank You!

### Manoj S

Hi, I'm Manoj working as a part-time blogger in Coding Diksha. Here, I post about programming to help developers.