Program to find Compound Interest in Java

Hello folks, today we will learn how to find compound interest in Java.

Compound Interest

Compound interest is the interest that is calculated on a particular principal, and also includes the interest gained over the periods the sum is being deposited.

I hope, you got the idea of compound interest and you solve mathematics problem related to it when you were in school. Even it was also in my mathematics when I was in school.

The formula for the amount for same is:

Amount = Principle*((1+rate/100)^time)

It is to be noted that the amount is paid out only once a year, that is, compounding frequency is one.

If the compounding frequency is more then the interest earned also increases, and so is the final amount.

Let us now go straight to the Java code to find the compound interest:

import java.util.*;
public class test
    public static void main(String args[]) 
        double principle,rate,time;
        Scanner sc = new Scanner(;
        System.out.println("Enter Priciple,Rate and Time ");
        double amount = principle *
        		(Math.pow((1 + rate / 100), time)); 
        System.out.println("Amount earned is "+ amount); 

The above code when executed will give the following result as the output:

Enter Priciple,Rate and Time 
Amount earned is 134009.56406250005
Enter Priciple,Rate and Time 
Amount earned is 61252.150000000016


Hope this helped you out.

Have a nice day ahead and even learn more.

Also Read:

Find the difference of days between two dates using Python

Split a string on the last occurrence of the delimiter using Python

A Java program to add some hours to current time


Leave a Reply

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