Page 102 - CA_Blue( J )_Class10
P. 102

are of different data types then the return value is converted into higher data type. Following are some examples of
              using the Math.min( ) method:
                 double m = Math.min(3.4, 4.2);            // output: 3.4
                 int i = Math.min(3, 6);                   // output: 3
                 double d = Math.min(3.4, 2);              // output: 2.0
              6.1.2 The Math.max( ) Method
              The Math.max( ) method is used to find the maximum number between two arguments passed to it. Similar to the
              Math.min( ) method, the return type of the Math.max( ) method depends on the types of arguments passed to it.
              Following are some examples of using the Math.max( ) method:

                 double m = Math.max(3.4, 4.2);            // output: 4.2
                 int i = Math.max(3, 6);                   // output: 6
                 double d = Math.max(3, 2.6);              // output: 3.0
              6.1.3 The Math.sqrt( ) Method
              The Math.sqrt( ) method is used to find the square root of the given number. It returns value in double and works only
              on positive numbers. Following are some examples of using the Math.sqrt( ) method:

                 double d = Math.sqrt(4)              // Output: 2.0
                 double d = Math.sqrt(8.1); // Output: 0.9
              If negative value is passed, the output will be NaN. For example,
                 double d = Math.sqrt(-9);            // Output: NaN
              6.1.4 The Math.cbrt( ) Method
              The Math.cbrt() method is used to find the cube root of the given number. It returns the value in double and works on
              both positive and negative numbers. Following are some examples of using the Math.cbrt( ) method:
                 double d = Math.cbrt(9.0); // Output: 2.080083823051904
                 double d = Math.cbrt(27);            // Output: 3.0
                 double d = Math.cbrt(-64); // Output: -4.0
              6.1.5 The Math.pow( ) Method
                                                                                                 n
                                                           th
              The Math.pow( ) method is used to calculate the n  power of a number m in the format of m . It returns the value in
              double data type and works on both positive and negative numbers. Following are some examples of using the Math.
              pow( ) method:
                 double d = Math.pow(3, 2); // Output: 9.0
                 double d = Math.pow(3, -2);          // Output: 0.1111111111111111
                 double d = Math.pow(-3, -2);         // Output: 0.1111111111111111
              6.1.6 The Math.log( ) Method
              The Math.log( ) method returns the logarithm of the provided value in the argument. It always returns a double type
              value and works on positive numbers only. If a negative value is passed, the output will be NaN. Following are some
              examples of using the Math.log( ) method:

                 double d= Math.log(5);               // Output: 1.6094379124341003
                 double d= Math.log(-6.25); // Output: NaN
              6.1.7 The Math.abs( ) Method
              The Math.abs( ) method returns the absolute value of the argument passed to it. It always returns a positive value and
              the return type depends on the type of argument passed to it. It can work on integer numbers as well as real numbers.
              The entered value may be positive or negative. For negative value:

                 double d = Math.abs(-3.8);           // Output: 3.8
                 int i = Math.abs(-4);                // Output: 4
              For positive value:
                 double d = Math.abs(3.2);            // Output: 3.2
                 int i = Math.abs(5);                 // Output: 5


                100100  Touchpad Computer Applications-X
   97   98   99   100   101   102   103   104   105   106   107