Page 144 - CA_Blue( J )_Class9
P. 144

7.2.3 Math.sqrt()
                  It is used to find the square root of the argument. It returns value in double. It works only on positive value. If
                  negative value is passed, it will return NaN.

                                            Examples of Math.sqrt ()                Output
                                     System.out.println(Math.sqrt(64));     8.0
                                     double d=Math.sqrt(0.49);              0.7
                                     double d = Math.sqrt(-9);              NaN

                  7.2.4 Math.cbrt()
                  It is used to find the cube root of the argument. It returns the value in double. It can work both on positive and
                  negative values.

                                            Examples of Math.cbrt ()                Output
                                     System.out.println(Math.cbrt(27.0));   3.0
                                     double d = Math.cbrt(125.9);           5.011971314649943
                                     double d = Math.cbrt(-27);             -3.0


                  7.2.5 Math.pow()
                                                                               b
                  It is used to return the “b” power of an argument “a” in the format a . It returns the value in double. It can work
                  on positive and negative values.

                                            Examples of Math.pow ()                 Output
                                     System.out.println(Math.pow(4,3));     64.0
                                     double d = Math.pow(2,-3);             0.125
                                     double d = Math.pow(-3,-2);            0.1111111111111111
                                                                            [explanation : 1.0/9.0]

                  7.2.6 Math.log()
                  It returns the logarithm of a value provided in the argument. It always returns a double type value. It works on
                  positive number only. If it is a negative, it produces a result as NaN.
                                             Examples of Math.log ()                Output
                                     System.out.println(Math.log(5));       1.6094379124341003

                                     double d = Math.log(-6.25);            NaN
                                     double d = Math.log(1/2);              -Infinity
                                     System.out.println(Math.log(60));      4.0943445622221

                  7.2.7 Math.abs()
                  It returns the absolute value of the argument. It always returns the positive value. It can work on integer as well as
                  real value. The value may be entered positive or negative. If a negative value is entered, the output would be positive.
                                             Examples of Math.abs()                 Output
                                     System.out.println(Math.abs(-34));     34
                                     int d = Math.abs(6);                   6
                                     double d = Math.abs(-1.0/2.0);         0.5
                                     System.out.println(Math.abs(-6.45));   6.45





                   142    Touchpad Computer Applications-IX
   139   140   141   142   143   144   145   146   147   148   149