Write a Java Program to Calculate Compound Interest with example. The formula behind Compound Interest calculation:

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

The above formula is to calculate Future Compound Interest because it contains both the Principal Amount and Compound Interest. To get the Compound Interest, use the 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 the total number of years. By using those values, this Java program finds 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 find Compound Interest Example 2

This Java program is the same as above. But this time, we are creating a 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**