#### Compound Interest Calculator

by

, January 29th, 2012 at 03:57 PM (7049 Views)
Compound interest can be calculated with the following formula.

A = Amount

P = Principal

R = Rate

n = Years

A=P(1+R)^n

We can calculate the amount in Java as shown below. We currently know the principal (10,000) and the rate (1%). The years can change depending on how much information we want. In this application, we'll just use 20.

We initialise our variables as per usual. We then construct a For Loop which will give us 20 iterations. Using our formula, we calculate theamount. We used theMath.powfunction because it allows us to use indices. The first parameter is what you want in the parentheses and the second parameter is what you want the power to be. Quite a simple calculator.