Compound interest java – Java Program to Calculate Compound Interest

Compound interest java: Don’t stop learning now. Get hold of all the important Java fundamentals with the Simple java program example guide and practice well.

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

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