In this article, we will show you, How write a Java Program to Calculate Compound Interest with example. Before we get into the program, let me show you the formula behind Compound Interest calculation:

Future Compound Interest = Principal Amount * ( 1 + Rate of Interest )^{Number of years})

Above formula is to calculate Future Compound Interest, because it contains both the Principal Amount, and Compound Interest. In order to get the Compound Interest use below formula:

Compound Interest = Future Compound Interest – Principal Amount

## Java Program to Calculate Compound Interest Example 1

This Java program allows the user to enter the Principal Amount, Interest Rate, and total Number of years. By using those values, this program will calculate the compound Interest using the above specified formula.

// Java Program to Calculate Compound Interest import java.util.Scanner; public class CompoundInterest { private static Scanner sc; public static void main(String[] args) { double PAmount, ROI, TimePeriod, FutureCI, CI; sc = new Scanner(System.in); System.out.print(" Please Enter the Principal Amount : "); PAmount = sc.nextDouble(); System.out.print(" Please Enter the Rate Of Interest : "); ROI = sc.nextDouble(); System.out.print(" Please Enter the Time Period in Years : "); TimePeriod = sc.nextDouble(); FutureCI = PAmount * (Math.pow(( 1 + ROI/100), TimePeriod)); CI = FutureCI - PAmount; System.out.println("\n The Future Compound Interest for Principal Amount " + PAmount + " is = " + FutureCI); System.out.println(" The Compound Interest for Principal Amount " + PAmount + " is = " + CI); } }

**OUTPUT**

## Java Program to Calculate Compound Interest Example 2

This Java program is same as above but this time we are creating separate method to calculate the compound Interest.

// Java Program to Calculate Compound Interest import java.util.Scanner; public class CompoundInterest1 { private static Scanner sc; public static void main(String[] args) { double PAmount, ROI, TimePeriod; sc = new Scanner(System.in); System.out.print(" Please Enter the Principal Amount : "); PAmount = sc.nextDouble(); System.out.print(" Please Enter the Rate Of Interest : "); ROI = sc.nextDouble(); System.out.print(" Please Enter the Time Period in Years : "); TimePeriod = sc.nextDouble(); calCompoundInterest(PAmount, ROI, TimePeriod); } public static void calCompoundInterest(double PAmount, double ROI, double TimePeriod) { double FutureCI, CI; FutureCI = PAmount * (Math.pow(( 1 + ROI/100), TimePeriod)); CI = FutureCI - PAmount; System.out.println("\n The Future Compound Interest for Principal Amount " + PAmount + " is = " + FutureCI); System.out.println(" The Compound Interest for Principal Amount " + PAmount + " is = " + CI); } }

**OUTPUT**

Thank you for visiting Our Blog