# Exponents in Java without Math.pow



## autokustomizer (Apr 1, 2009)

I am working on a problem that is simulating an IRA account. Someone enters their initial deposit, and then that number needs to be calculated out to a certain number of years. Is there any way to take a number to a power of itself without using the Math.pow?? I realized that by using this statement,
{CODE} whenS = (44 * (initialDep * (1 + interest))); {CODE}, I am not getting the correct answer, because after 44 years the compounded interest isn't calculated that way, but I cannot use the pow statement. I appreciate any ideas....I was thinking to use a loop to calculate it out...but I am still at the delima of not knowing how to use exponents without the pow. Thank you


----------



## NeonFx (Oct 22, 2008)

See if this works:

x ^ y


```
do {
   x *= x;
   temp++;
}while(temp < (y-1));
temp = 0;
```
I might be wrong with the logic, but if you can read that then you know what you have to do.


----------



## autokustomizer (Apr 1, 2009)

Thank you, but I think I figured out a way to do it without a loop...Check it out

{CODE}
whenS = (initialDep * Math.exp((1 + interest) * Math.log(44)));
whenSo = (initialDep * Math.exp((1 + interest) * Math.log(45)));
interestWithdrawn = (((whenSo * interest) + whenSo) - whenSo);

{CODE}


----------



## NeonFx (Oct 22, 2008)

Well you should've said I could use the Math class. Glad you got it :up:


----------

