//try this
System.out.println(Math.pow((double)5,1.0d/2));
//Math.pow((double)a,1.0d/n));
//* Please mark this post as helpful if the code is suitable for you
public static double pow(double a,double b)
Math.pow requires two double literals as input.
An integer literal is divided by integer literal give a result of integer literal.
int top=11;
int bottom=2;
System.out.println("top/bottom= "+top/bottom);
//--> top/bottom= 5 (the result is trancated)
Look at here for some rules
so Math.pow(5,1/2) gives result of 1.0d because 5 to power of 0 is 1. 1/2 gives 0.
Math.pow((double)a,1.0d/n));
A double literal divided by any literal number(except 0) give double result, so n need not to be casted--> (double)n
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.