Program to calculate Compound Interest in Java?


 Program to calculate Compound Interest in Java?

This is a common program that will be asked by multiple interviewers from freshers and experienced both.

most of the students work on SI but they not comfortable with SI Calculation but not know Compound Interest Calculation easily.

We will use Math.pow() function to calculate CI.

Math.pow() has two parameters, the first parameters will be base and the second parameters will be an exponent.


Formula will be  = principal * (Math.pow(1+(r/100),n*t)

Complete program to calculate compound interest?

import java.util.Scanner;

class CI


public static void main(String args[])


       float p,r,t,n,a;

       double total;

       Scanner sc = new Scanner(;

       System.out.println("Enter p");


       System.out.println("Enter r");


       System.out.println("Enter t");


       System.out.println("Enter number of time for interest");


       total = p*(Math.pow((1+r/100),(n*t)));

       System.out.printf("actual amount is %.2f, Total amount %.2f, Total interest 

is %.2f ",p,total,(total-p));



Post a Comment


POST Answer of Questions and ASK to Doubt

Post a Comment (0)