Hello all. I've a question regarding using fractions as exponents. Not quite sure how to start this in Java.
For example, let's say someone gives you an equation from an excel sheet as follows:
(AxB)^1/3
I'm assuming this means multiplying A*B then raising it to the power of 1/3 (one third). How would one go about writing this in Java math? I don't think I've ever working with fractions as exponential powers before.
I've attempted to convert it to a decimal value however the math doesn't seem to come out correctly. I've also tried it on the regular calculator, but the calc I have on hand is fairly limited.

Any help would be greatly appreciated. Or a point in the right direction.
Tnx

What code did you use?
If I understood correctly, you need to know how to do this: a^b

double a = 8.0;
double b = 1.0/3.0;

double r = Math.pow(a,b);

System.out.println(r);

Check the API for the class: java.lang.Math for more.

What code did you use?
If I understood correctly, you need to know how to do this: a^b

double a = 8.0;
double b = 1.0/3.0;

double r = Math.pow(a,b);

System.out.println(r);

Check the API for the class: java.lang.Math for more.

I tried something similar but I wasn't using a double... which now I see I should have.
I'll give it a shot and see how things come out.
I was going by reference examples at this link: http://www.cafeaulait.org/course/week4/40.html

Thanks for the reply and help.
Much appreciated.

This article has been dead for over six months. Start a new discussion instead.