Home | Blog | Java | Jokes | Poems | Musings | Site Map | Kudos | Downloads | Useful Sites | Interesting | System Setup | Contact

Home Page

AKGBackup - The backup program

            

 

Section 9 : The java.lang Package

 


 

Write code using the following methods of the java.lang.Math class: abs, ceil, floor, max, min, random, round, sin, cos, tan, sqrt.

 


 

 

Math

 

It is a final class having a private constructor. All of its methods are static.

 

Fields:

 

  • static double E

  • static double PI

 

Methods:

 

  • type abs (type t)

type is double, float, int and long. Return type and argument type are same. In case of int and long versions, if respective MIN_VALUE is the argument then same is returned. In case of float and double versions if argument is positive or negative zero, positive zero is returned. If argument is infinite, positive Infinity is returned. If argument is NaN, the result is NaN.

  • double ceil (double d)

returns the smallest (closest to negative infinity) double value that is not less than the argument and is equal to a mathematical integer. Special cases:

If argument is equal to an integer, same is returned.

If argument is NaN, +Infinity, -Infinity, +0, or –0, the result is same as argument.

If argument is less than zero but greater than –1.0, result is –0.0

  • double floor (double d)

returns the largest (closest  to positive infinity) double value that is not greater than the argument and is equal to mathematical integer.

Return values are same in special cases as that in ceil() except there is no third case.

  • double cos (double d)

d is in radians. If argument is NaN or infinity, result is NaN.

  • type max (type t1, type t2)

type is int, float, long or double. Return type is same as argument type. Returns the greater of the two values. For float and double versions:

if either of the arguments is NaN, NaN is returned.

Unlike the numerical comparison operators, here –0.0 is smaller than +0.0

  • type min (type t1, type t2)

returns the smaller of the two values. Rest of the discussion is same as max().

  • double random ()

returns double value between +0.0 and 1.0 (exclusive). This method is properly synchronized to allow correct use by more than one thread.

  • double rint (double d)

returns the closest double value to argument and is equal to an integer.

  • long round (double d)

return the closest long value to the argument.

If argument is NaN, result is zero.

If argument is –Infinity or any value less than or equal to the value of Long.MIN_VALUE, the result is equal to Long.MIN_VALUE.

If argument is +Infinity or >= Long.MAX_VALUE, then the result is Long.MAX_VALUE.

  • int round (float f)

return the closest long or int values to the argument respectively.

If argument is NaN, result is zero.

If argument is –Infinity or any value less than or equal to the value of Integer.MIN_VALUE, the result is equal to Integer.MIN_VALUE.

If argument is +Infinity or >= Integer.MAX_VALUE, then the result is Integer.MAX_VALUE.

  • double sqrt (double d)

returns the correctly rounded positive square root of a double value.

If the argument is NaN or less than zero, then the result is NaN.

If the argument is positive infinity, then the result is positive infinity.

If the argument is positive or negative zero, then the result is same as the argument.

  • double sin (double d)

d is in radians. If argument is NaN or infinity, result is NaN.

  • double tan (double d)

same as sin().

  • double toRadians (double angDeg)

  • double toDegrees (double angRad)

 

 


 

section9-1 | section9-2

 

Sections : 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11

 

 

 

 

 

 

 

Home | Blog | Java | Jokes | Poems | Musings | Site Map | Kudos | Downloads | Useful Sites | Interesting | System Setup | Contact  

Loading

 Number of Pages viewed on this site since January' 2003 : Hit Counter eXTReMe Tracker

For any queries, comments or suggestions, write to me .

This site never compromises your privacy, please read this site's privacy policy.