**Java program to calculate compound interest** is a simple program to calculate compound interest.

In this tutorial, we will learn what is mean by compound interest, how to calculate compound interest, compound interest formula, and Java program to find compound interest, compound interest problems.

Let’s see the first introduction to compound interest

**Compound interest definition?**

Compound interest is calculated on

- Initial the principal amount
- Interest on investment of previous periods of the loan.

**Compound Interest formula –**

Let’s see compound interest formula

**Compound interest = Principal((1+rate/n)^(n*time))**

Where the principal is the principal amount to be invested

The rate is a rate of interest

N is no of days amount investment

Times is number of time compounded

**Example:-**

Principal = 5000

Rate = 5

No of year = 10

Times = 12

now calculate compound interest

Compound interest =Principal((1+rate/n)^(n*time))

Compound interest = 8235.04

**The logic to calculate compound interest in c programming :**

First, we take an input principal, rate, no of years, and times from user and using compound interest formula we calculate compound interest and print the result.

**The algorithm to calculate compound interest **

- Start
- Declare variables
- Assign values
- Calculate compound interest using formula.
- print Compound interest
- Stop

## Java program for compound interest

1 2 3 4 5 6 7 8 9 10 11 12 |
public class Main { public static void main(String[] args) { double principle = 10000, rate = 10.25, time = 5; /* Calculate compound interest */ double CI = principle * (Math.pow((1 + rate / 100), time)); System.out.println("Compound Interest is "+ CI); } } |

**Output :**

**Explanation :**

**1. First we write class**

**2. Declare variables**

principal => to store principal amount

rate => to store rate of interest

time => to store no of years for compound interest

**3. ****Next using formula calculate compound interest**

**compoundInterest=(float)(principal*(pow((1+(rate/(100*n))),(n*time))));**

This is a simple way to write a expression in c programming.

compoundInterest=(float)(5000*(pow((1+(5/(100*12))),(12*10))));

compoundInterest = 8235.047852

**7. Next print the compound interest that we calculated using formula.**

printf(“Compound Interest is %f\n”,compoundInterest);

=> Compound Interest is 8234.047852

Also Read:

- Factorial of a number
- Sum of n numbers
- Sum of digits in a number
- Palindrome number in java
- Fibonacci series program
- Armstrong number in java

## Leave a Reply