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

package com.tcc.java.programs;

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(System.in);
        // 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);
    }
}
Output
Enter Amount
10000
Enter Duration in Years
3
Enter Rate of Interest
10
Compound Interest = 3310.000000

Recommended Posts
Java Program to Calculate Simple Interest
Java Program to Make a Simple Calculator using Switch Statement
Java Program to calculate area and circumference of circle
Java Program to Convert Decimal to Binary Numbers
Java program to convert binary number to decimal number
Java Program to Convert Fahrenheit to Celsius
Java Program to Find LCM and GCD of Two Numbers
Java Program to Check Perfect Number or Not
Java Program to Check a Number is Prime Number or Not
Java Program to Print Pascal Triangle
Java Program to find Area Of Equilateral Triangle
All Java Programs