Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Converting from formulas to java code Math.pow

1. ## Converting from formulas to java code Math.pow

Hi guy,

I am new to Java and working on converting these two formulas to Math.pow. I do not think what I did is right. I would really appreciate your comment.

1- z equal ((x^(2)*5y)^(24))/(\sqrt(y))

I tried Mat.pow (x,2) * (5*y) *24 / Math.pow (y * 0.5)

2- z equal ((x^(2)*5y)^(24))/(xy)

I tried ((Math.pow (x,2) * 5 * y), 24 ) /(x*y)  Reply With Quote

2. ## Re: Converting from formulas to java code Math.pow

Hi Bandar,

For the first question:

It should be Math not Mat.  Reply With Quote

3. ## Re: Converting from formulas to java code Math.pow

In both cases there are two '^' operators in the numerator (top) of the fraction, so I would expect two uses of Math.pow in each numerator. But you only have one.

Break the expressions up into small pieces and translate one at a time into code. Eg

x squared ... times 5y ... to the power of 24 ... all divided by the square root of y

---

If you think something is wrong, say what it is: unexpected answer, runtime exception, compiler message, etc.  Reply With Quote

4. ## Re: Converting from formulas to java code Math.pow

I see. There is a power twice. x, y. How to write it correctly to come away with the correct answer? How much different answers were there? A lot? Math.pow  Reply With Quote

5. ## Re: Converting from formulas to java code Math.pow

I think you might be getting an incorrect ans because of 4/3 in Integer Math give 1 and not 1.33 Try changing you code to what is give below. I tried and worked fine for me.  Reply With Quote 