Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: How can I calculate the balance with this formula in java program

1. ## How can I calculate the balance with this formula in java program

If you deposit p dollars, the money in your account after n years at an interest rate r is p (1 + r)^n

This is what I got.... Is this correct? and would I need to cast this beacause years are in int variable?

double balance;
double dollars;
double interestRate;
int years;

balance = dollars * Math.pow((1 + interestRate), years);

• years does need to be in double form- whether you convert or cast in this situation i think depends on your style since double is more precise than int and there should be no chance of data loss (I could be wrong though)

Edit: Math.pow(double a, double b) is expected

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•