Like Us Like Us Facebook Subscribe Subscribe us YouTube Whatsapp Share us Whatsapp Query Send your queries

How to make a Compound Interest Calculator using Java

How to make a Compound Interest Calculator using Java

This tutorial deals with how to calculate compound interest in Java. This was given an small assignment to one of my student Abhijit . This  tutorial is idle for those who have just started learning java. In upcoming tutorial I will try to convert this command line application to simple GUI.

Compound Interest Formula

CI = P (1 + r/n) (nt) – P
P = the principal investment amount (the initial deposit or loan amount)
r = the annual interest rate (decimal)
n = the number of times that interest is compounded per year
t = the number of years the money is invested or borrowed for

Screen shot

compound interest java


Compound Interest Java Code :

import P= Principle, r=Rate (Annual) ,t= Time Period, n= Frequency of calculation in one*;
* By Abhijit Prasad (Student)
* Simple Interest Calculator
class Compoundinterest{
public static void main(String args[]){
double p,r;
int t, n;
Scanner inp=new Scanner(;
System.out.println("Enter the Principle: ");
p= inp.nextDouble();
System.out.println("Enter the Rate: ");
r = inp.nextDouble();
System.out.println("Enter the Time Period: ");
System.out.println("Enter the Frequency: ");
double ci=compInterest(p,r,t,n);
ci = java.lang.Math.round(ci);
System.out.println("Calculated Compund Interest: "+ci);
public static double compInterest(double pr, double ra, int t, int freq){
double ci= pr*java.lang.Math.pow(1+ra/(100*freq),freq*t);
return ci-pr;

0 0 votes
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments