ADVERTISEMENT
ADVERTISEMENT

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

Java Basic Programs »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.