Java2all.com  

Math Class





Share This Topic -

Math Class :
  • For scientific and engineering calculations, a variety of mathematical functions are required.
  • Java provides these functions in the Math class available in java.lang package.
  • The methods defined in Math class are given following:

Method

Description

Double sin(double x)

Returns the sine value of angle x in radians.

Double cos(double x)

Returns the cosine value of the angle x in radians

Double tan(double x)

Returns the tangent value of  the angle x in radians

Double asin(double x)

Returns angle value in radians for arcsin of x

Double acos(double x)

Returns angle value in radians for arcos of x

Double atan(double x)

Returns angle value in radians for arctangent of x

Double exp(double x)

Returns exponential value of x

Double log(double x)

Returns the natural logarithm of x

Double pow(double x, double y)

Returns x to the power of y

Double sqrt(double x)

Returns the square root of x

Int abs(double n)

Returns absolute value of n

Double ceil(double x)

Returns the smallest wholoe number greater than or equal to x

Double floor(double x)

Returns the largest whole number less than or equal to x

Int max(itn n, int m)

Returns the maximum of n and m

Int min(int n, int m)

Returns the minimum of n and m

Double rint(double x)

Returns the rounded whole number of x

Int round(float x)

Returns the rounded int value of x

Long round(double x)

Returns the rounded int value of x

Double random()

Returns a random value between 0 and 1.0

Double toRandians(double angle)

Converts the angle in degrees to radians

Double toDegrees(double angle)

Converts the angle in radians to degrees

EX :

 public class Angles 
{
	public static void main(String args[]) 
	{
		double theta = 120.0;
		System.out.println(theta + " degrees is " + Math.toRadians(theta) + " radians.");
		theta = 1.312;
		System.out.println(theta + " radians is " + Math.toDegrees(theta) + " degrees.");
	}
}

 
Output :
 
120.0 degrees is 2.0943951023931953 radians.
1.312 radians is 75.17206272116401 degrees.