# beginner grade 11-need help with a math code involving returning values from a method

• 12-10-2008, 12:40 AM
bobmasta5
beginner grade 11-need help with a math code involving returning values from a method
My following code is to calculate the monthly payment of someones mortgage. I was given the formula:
payment = loan * (rate/100/12) / ( 1 - ( 1 / ( 1 + (rate/100/12) )) ^ (years * 12 ))

How can I substitute the '^' with Math.pow in order to get this equation to work in my code.
• 12-10-2008, 01:50 AM
Nicholas Jordan
Code:

```    public static double pow(double a, double b) {         return StrictMath.pow(a, b); // default impl. delegates to StrictMath     }```
There are special casing issues for various situations, this should get you unstuck...
• 12-10-2008, 02:00 AM
bobmasta5
Im not really sure how to do it still. Its my first year programming and Math.pow is suppose to replace the '^' somehow without nothing to technical.
• 12-10-2008, 02:38 AM
Nicholas Jordan
you have to sit there and pencil and paper your way through it...

double years = ?....
double twelve = new Double(12.0000);

( rate divided by 100 divided by 12 )

divided by .... start with the innermost round braces and work your way out, keep careful detail on exactly when each round brace closes, it is programmed by carefully working that one pair at a time:

one plus (rate/100/12) then one is divided by that number then.....

tedious, error-prone, yes.

do homework, no.