Q:

Java program to calculate compound interest

0

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

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now