# Use of Math.pow?

Ogwal Boniface

Greenhorn

Posts: 7

Ulf Dittmer

Rancher

Posts: 42967

73

Ogwal Boniface

Greenhorn

Posts: 7

Ulf Dittmer

Rancher

Posts: 42967

73

Ogwal Boniface

Greenhorn

Posts: 7

posted 6 years ago

Hi Ulf,

Thanks alot for replying.

Your code:

What I did:

The output is: The amount at the end of year 11 is:52500.0

This amount is correct but why does it print year 11?

Also, how could I use this amount as the value of P for the second and so on till the 10th year?

I am a complete newbie in the Java world but please help.

Thanks alot

Thanks alot for replying.

Your code:

What I did:

The output is: The amount at the end of year 11 is:52500.0

This amount is correct but why does it print year 11?

Also, how could I use this amount as the value of P for the second and so on till the 10th year?

I am a complete newbie in the Java world but please help.

Thanks alot

~~Great minds read, ask and then share~~

Ulf Dittmer

Rancher

Posts: 42967

73

posted 6 years ago

That code doesn't even compile; are you sure it's the code that you're running? If you fix the syntax errors to make it compile, then it will indeed run from 1 to 10 for n. What's still missing is that the formula for "a" isn't what's mentioned in the description (and hence doesn't change for higher "n").

posted 6 years ago

[ UD: Thanks for your contribution, but we don't want to rob Ogwal of an opportunity to learn: JavaRanch is NotACodeMill ]

Priety.

Ogwal Boniface

Greenhorn

Posts: 7

posted 6 years ago

Hi Ulf & Priety,

Thanks for the comments. I have taken note.

Below is my refined code:

The ouput iterates ten times, incrementing 'n' but keeping same value of 'a'.

Kindly help me understand how I can increment 'n' first, before 'a' is calculated based on the formula.

Also, is there a way I could use the output when 'n=1' as the value of P when 'n=2' and so on till year 10?

**Priety**..I understand the meaning of JavaRanch is 'NotACodeMill http://faq.javaranch.com/java/NotACodeMill' but I am trying to come up atleast with something as per what I know so far...

Thanks again for the time. It's appreciated

Thanks for the comments. I have taken note.

Below is my refined code:

The ouput iterates ten times, incrementing 'n' but keeping same value of 'a'.

Kindly help me understand how I can increment 'n' first, before 'a' is calculated based on the formula.

Also, is there a way I could use the output when 'n=1' as the value of P when 'n=2' and so on till year 10?

**Priety**..I understand the meaning of JavaRanch is 'NotACodeMill http://faq.javaranch.com/java/NotACodeMill' but I am trying to come up atleast with something as per what I know so far...

Thanks again for the time. It's appreciated

~~Great minds read, ask and then share~~

Ulf Dittmer

Rancher

Posts: 42967

73

Ogwal Boniface

Greenhorn

Posts: 7

posted 6 years ago

Hi Ogwal,

I have a doubt.

As far as I understand your requirement is like this:

Calculate the interest for 1 year on the beginning principal of 50000 using rate of interest as 5%.

Then for the 2nd year add the interest to the principal and recalculate the interest on it at 5% and so on for 10 years.

Is this right?

Then the calculation should show the following results:

The amount at the end of the 1 th year is:52500.0

The amount at the end of the 2 th year is:55125.0

The amount at the end of the 3 th year is:57881.2

The amount at the end of the 4 th year is:60775.3

The amount at the end of the 5 th year is:63814.0

When I ran your code the results were:

The amount at the end of the 1 th year is:52500.0

The amount at the end of the 2 th year is:57881.2

The amount at the end of the 3 th year is:67004.7

The amount at the end of the 4 th year is:81444.7

The amount at the end of the 5 th year is:103946.4

So is that code producing the right results?

Just curions.

Correct me if I am wrong.

I have a doubt.

As far as I understand your requirement is like this:

Calculate the interest for 1 year on the beginning principal of 50000 using rate of interest as 5%.

Then for the 2nd year add the interest to the principal and recalculate the interest on it at 5% and so on for 10 years.

Is this right?

Then the calculation should show the following results:

The amount at the end of the 1 th year is:52500.0

The amount at the end of the 2 th year is:55125.0

The amount at the end of the 3 th year is:57881.2

The amount at the end of the 4 th year is:60775.3

The amount at the end of the 5 th year is:63814.0

When I ran your code the results were:

The amount at the end of the 1 th year is:52500.0

The amount at the end of the 2 th year is:57881.2

The amount at the end of the 3 th year is:67004.7

The amount at the end of the 4 th year is:81444.7

The amount at the end of the 5 th year is:103946.4

So is that code producing the right results?

Just curions.

Correct me if I am wrong.

Priety.

Campbell Ritchie

Sheriff

Posts: 48386

56

Ogwal Boniface

Greenhorn

Posts: 7

posted 6 years ago

Hi Prietty,

Below is my complete code and the subsequent output:

My main problem is to use like the value of year1 in the output as the value of P for the second year and so on, giving something as below:

year 1 is 52,500.00

year 2 is 57,881.25

year 3 is 67,004.78

year 4 is 81,444.73

year 5 is 103,946.41

year 6 is 139,298.13

year 7 is 196,006.46

year 8 is 289,590.81

year 9 is 449,250.39

year 10 is 731,781.55

Grateful for further assistance

Regards

Below is my complete code and the subsequent output:

My main problem is to use like the value of year1 in the output as the value of P for the second year and so on, giving something as below:

year 1 is 52,500.00

year 2 is 57,881.25

year 3 is 67,004.78

year 4 is 81,444.73

year 5 is 103,946.41

year 6 is 139,298.13

year 7 is 196,006.46

year 8 is 289,590.81

year 9 is 449,250.39

year 10 is 731,781.55

Grateful for further assistance

Regards

~~Great minds read, ask and then share~~