Skip to main content

Posts

Showing posts with the label ICSE

Java Mathematical Library Notes

Mathematical Library ---------------------- The math library is present under the package java.lang. Not under the package java.math . 1) Math.sqrt() -> return type is double. It returns the square root of a number. (a) double x = Math.sqrt(4);  => 2.0 (b) double y = Math.sqrt(-4); => NaN (Not a number) (for any negative value the answer is always NaN) 2) Math.cbrt() -> return type is double. It returns the cube root of a number (a) double x = Math.cbrt(8); => 2.0 (b) double y = Math.cbrt(-125); => -5.0 3) Math.pow() -> return type is double  Syntax:  Math.pow(base,exponent) 5 to the power of 3 (here 5 is base and 3 is exponent) (a) double x = Math.pow(5,3); => 125.0 (b) double y = Math.pow(16,1/2); => Math.pow(16,0); => 1.0     here 1/2 is 0 (L<R,/,0 when both are integer) (c) double z = Math.pow(16,1.0/2); => Math.pow(16,0.5) => 4.0 (d) double a = Math.pow(-16,1.0/2); => NaN  (e) double b = Math.pow(64,1.0/3); =...