Compound Interest Java Program
Java Code:
import java.util.*;
public class compoundInterest {
/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated
method stub
Scanner
input = new Scanner(System.in);
System.out.print("Enter the
Initial Investment: ");
double Iv =
input.nextInt();
System.out.print("Enter Annual
Interest Rate in % : ");
double Ap =
input.nextInt();
System.out.print("Enter Number
of years: ");
double Ny =
input.nextInt();
System.out.println("Year" +" " +"Beginning Balance"+" "+" "+"Interest"+" "+" "+ "Ending
Balance");
for(int i=1; i<=Ny;i++){
double in=(Iv*Ap)/100;
double ou=(Iv+in);
System.out.printf(i+ " "+" "+" "+ " "+"%.2f", Iv );
System.out.printf(" "+" "+" "+" "+" "+" "+" "+" "+" "+" "+" "+" "+ "%.2f", in );
System.out.printf(" "+" "+" "+" "+"%.2f", ou );
System.out.println();
Iv=ou;
}
}
}
No comments:
Post a Comment