java.lang.Math.sqrt() devuelve la raíz cuadrada de un valor de tipo double que se le pasa como argumento. Si el argumento es NaN o negativo, entonces el resultado es NaN. Si el argumento es infinito positivo, entonces el resultado es infinito positivo. Si el argumento pasado es cero positivo o cero negativo, el resultado será el mismo que el del argumento.
base de datos java jdbc
Sintaxis :
public static double sqrt(double a) Parameter : a : the value whose square root is to be returned. Return : This method returns the positive square root value of the argument passed to it.>
Ejemplo 1 : Para mostrar el funcionamiento de java.lang.Math.sqrt() método.
// Java program to demonstrate working> // of java.lang.Math.sqrt() method> import> java.lang.Math;> > class> Gfg {> > > // driver code> > public> static> void> main(String args[])> > {> > double> a => 30> ;> > > System.out.println(Math.sqrt(a));> > > a => 45> ;> > > System.out.println(Math.sqrt(a));> > > a => 60> ;> > > System.out.println(Math.sqrt(a));> > > a => 90> ;> > > System.out.println(Math.sqrt(a));> > }> }> |
>
>
Producción:
5.477225575051661 6.708203932499369 7.745966692414834 9.486832980505138>
Ejemplo 2 : Para mostrar el funcionamiento de java.lang.Math.sqrt() método cuando el argumento es NaN o +infinito.
marca de agua en word
// Java program to demonstrate working> // of java.lang.Math.sqrt() method> import> java.lang.Math;> // importing java.lang package> > public> class> GFG {> > public> static> void> main(String[] args)> > {> > > double> positiveInfinity = Double.POSITIVE_INFINITY;> > double> negativeVal = -> 5> ;> > double> nan = Double.NaN;> > double> result;> > > // Here argument is negative,> > // output will be NaN> > result = Math.sqrt(negativeVal);> > System.out.println(result);> > > // Here argument is positive infinity,> > // output will also positive infinity> > result = Math.sqrt(positiveInfinity);> > System.out.println(result);> > > // Here argument is NaN, output will be NaN> > result = Math.sqrt(nan);> > System.out.println(result);> > }> }> |
q3 meses
>
>
Producción:
NaN Infinity NaN>