( 273 )
331 multiply t+273/273 the result is exponent 1/2
how do you write this equation in java using math.class
. . . or 0.3333333333333333333333333333333333333333333 because there is a cube root method too.
Rob Spoor wrote:There's also a method Math.pow which takes two doubles. You could use that if the exponent is a fraction other than 0.5.
Don't use Math,pow(x, 2) for squares. Use x * x instead.
Rob Spoor and Campbell Ritchie: so can i use math.pow in this particular ecuation or just math.sqrt
and can you tell if this is right or wrong : 331*(math.sqrt((t*273)/273)
or can you guys write this ecuation using math class please.
thanks a lot
There is no such thing as a 'math' class in java. There is, however, a Math class.
So, Math.sqrt(331 * ...) and not 331 * Math.sqrt(...)
Beware of integer arithmetic: for any t such that t < 273 and t ≥ 0, the result of the division will turn out to be 1, if t is an integer.
static double sqrt(double a)
Returns the correctly rounded positive square root of a double value.
so if you want the square root, you use this.
static double pow(double a, double b)
Returns the value of the first argument raised to the power of the second argument.
If you want to raise a number to some arbitrary power, you use this.
Since raising a number to the 1/2 power is BY DEFINITION taking the square root, you can use either one you want.
The reason is that 1 / 2 is integer arithmetic, and will return 0, so you will get x to the power of 0, and that returns 1.
I would say, if they have got a method which is specially designed for square roots, use that method. It's easier for a start.