Java Program to Calculate Compound Interest

  • Java program to find the Compound interest.

In this java program to calculate compound interest, we first take amount, rate of interest and duration in year as input from user and use following equation to calculate compound interest.

How to Calculate Compound Interest ?
Amount = P x (1 + R/100)T
Compound Interest = Amount - P
Where P, R and T are Principle, Rate of Interest and Time respectively.

Java program to calculate compound interest


import java.util.Scanner;

 * Java Program to calculate Compound Interest
class CompoundInterest {
    public static void main(String[] args) {
        double principal, time, rate, CI;

        Scanner scanner = new Scanner(;
        // Taking input from user
        System.out.println("Enter Amount");
        principal = scanner.nextDouble();

        System.out.println("Enter Duration in Years");
        time = scanner.nextDouble();

        System.out.println("Enter Rate of Interest");
        rate = scanner.nextDouble();
        // Calculate Compound Interest
        CI = principal * Math.pow(1.0 + rate / 100.0, time) - principal;

        System.out.format("Compound Interest = %f", CI);
Enter Amount
Enter Duration in Years
Enter Rate of Interest
Compound Interest = 3310.000000