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
Program to find compound interest in java
Output