Math

The java.lang.Math Class The java.lang.Math class encapsulates basic mathematical operations.
  public final static double Math.PI Defined constant for PI
  public final static double Math.E Define constant for e.
Exam Tip All methods in the Math class are defined as static.

Most return a value of double.

abs() public static int abs(int a)

public static long abs(long a)

public static float abs(float a)

public static double abs(double a)

The absolute methods return the absolute value of the argument. abs() method is overloaded.
ceil() public static double ceil(double a) The ceil() method takes the argument and rounds it up to the nearest highest Integer equivalent.

Aims for the next highest integer.

    Math.ceil(9.0) returns 9.0

Math.ceil(8.4) returns 9.0

Math.ceil(8.8) returns 9.0

Math.ceil(-9.0) returns -9.0

Math.ceil(-9.4) returns -9.0

Math.ceil(-9.8) returns -9.0

floor() public static double floor(double a) The floor() method takes the argument and truncated to the nearest lowest Integer equivalent.

Aims for the next lowest integer.

    Math.floor((9.0) returns 9.0

Math.floor((9.4) returns 9.0

Math.floor((9.8) returns 9.0

Math.floor((-9.0) returns -9.0

Math.floor((-8.4) returns -9.0

Math.floor((-8.8) returns -9.0

max() public static int max(int a, int b)

public static long max(long a, long b)

public static float max(float a, float b)

public static double max(double a, double b)

The max() method compares two arguments and returns the maximum of the two. Its overloaded.
min() public static int min(int a, int b)

public static long min(long a, long b)

public static float min(float a, float b)

public static double min(double a, double b)

The min() method compares two arguments and returns the minimum of the two. Its overloaded.
random() public static double random() The random() method returns a double number between 0.0 (inclusive) and 1.0 (exclusive). >=0.0 and < 1.0.
round() public static int round(float a)

public static int round(double a)

Rounds a number. The algorithm adds .5 to the argument and truncates to the nearest Integer.
    If the decimal argument is .5 or less Math.round(arg) is equal to Math.floor(arg).
    If the decimal argument is greater or equal to .5 Math.round(arg) is equal to Math.ceil(arg).
sin() public static double sin(double a) Returns the sine of an angle. The angle is given in radians.
     
Exam Tip

 

Math.toRadians( int degrees ) The Math.toRadians(arg) is used to convert degrees to radians.
     
cos() public static double cos(double a) Returns the cosine of an angle. The angle is given in radians.
tan() public static double tan(double a) Returns the tangent of an angle. The angle is given in radians.
sqrt() public static double sqrt(double a) Returns the square root of a number.

 

    NaN is returned if the number is negative.
acos()

asin()

atan()

atan2()

Returns the arc cosine of an angle.

Returns the arc sine of an angle.

Returns the arc tangent of an angle.

Returns the arc Polar coordinate of the input Cartesian coordinate.

exp() public static double exp(double a) Returns the value of the constant e raised to the power of the input parameter.
log() public static double log(double a) Returns the logarithm of the input parameter. The logarithm uses the constant e.
pow() public static double pow(double a, double b) The pow returns the first argument raised to the power of the second argument.
rint() public static double rint(double a) Returns the closest Integer equivalent to the argument.

 

    Values < .5 returns the least integer.

Values > .5 returns the highest integer.

Math.rint(7.4): 7.0

Math.rint(7.6): 8.0

Math.rint(8.4): 8.0

Math.rint(8.6): 9.0

Values of .5 behave as so:

The work in a consecutie odd even pair and return values of multiple 2’s: 2, 4. 6, 8 10. See example below

 

Math.rint(1.5): 2.0

Math.rint(2.5): 2.0

Math.rint(3.5): 4.0

Math.rint(4.5): 4.0

Math.rint(5.5): 6.0

Math.rint(6.5): 6.0

Math.rint(7.5): 8.0

Math.rint(8.5): 8.0

Math.rint(9.5): 10.0

Math.rint(10.5): 10.0

Math.rint(11.5): 12.0

Math.rint(12.5): 12.0

Math.rint(13.5): 14.0

Math.rint(14.5): 14.0

Math.rint(15.5): 16.0

Exam Tip rint() is bound to be on the exam. Know this
     
toDegrees() public static double toDegrees( double d) Returns an angle in degrees from argument given in radians.
toRadians() public static double toRadians( double d) Returns an angle in radians from argument given in degrees..
     
Wrapper Each primitive data type as corresponding wrapper class in the java.lang package.
  These classes allow the creation of object types for the primitives.
  Byte

Short

Character

Integer

Long

Float

Double

Boolean

     
Exam Tip What is the range of sin method:

-PI/2 to PI/2

0.0 to 360 degrees