Home » Java programs » Java basic programs

Java program to calculate compound interest



In this java program, we are going to learn how to calculate compound interest? Here, we are reading principle, rate and time and calculating compound interest.
Submitted by IncludeHelp, on November 19, 2017

Given principle, rate and time and we have to find compound interest using java program.

Example:

    Enter Principal : 5000
    Enter Rate : 5
    Enter Time : 3
    Amount : 5788.125000000001
    Compound Interest : 788.1250000000009

Program to find compound interest in java

import java.util.Scanner;

public class CompoundInterest 
{
	public static void main(String args[])
	{
		// declare and initialize here.
		double A=0,Pri,Rate,Time,t=1,CI;
		
		// create object.
		Scanner S=new Scanner(System.in);
		
		// enter principal, rate, time here
		System.out.print("Enter Principal : ");
		Pri=S.nextFloat();
		
		System.out.print("Enter Rate : ");
		Rate=S.nextFloat();
		
		System.out.print("Enter Time : ");
		Time=S.nextFloat();
		
		Rate=(1 + Rate/100);
		for(int i=0;i<Time;i++)
			t*=Rate;
		
		A=Pri*t;
		System.out.print("Amount : " +A);
		CI=A-Pri;
		System.out.print("\nCompound Interest : " +CI);	
	}
}

Output

First run:
Enter Principal : 5000
Enter Rate : 5
Enter Time : 3
Amount : 5788.125000000001
Compound Interest : 788.1250000000009

Second run:
Enter Principal : 10000
Enter Rate : 20
Enter Time : 5
Amount : 24883.199999999997
Compound Interest : 14883.199999999997





Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.



Comments and Discussions


We are using Google to publish ads on our website; Google has its own privacy policies. They may save log, cookies on your system. Google may also collect information of your system like IP address, region, city, country. For more details please go through the Google’s privacy policy.