What are the methods of Math classes commonly used in JAVA?

The Math class is a class that contains many mathematical constants and calculation methods. The methods in it are all static methods. The Math class is located under the java.lang package and can be imported automatically

Common methods of Math class in Java
Mathematical constant:
Common methods:
Seeking random numbers
Absolute value
Maximum value
Minimum value
Rounding
Rounding
Nearest integer
Trigonometric calculation
Inverse trigonometry
Square root calculation
Logarithmic calculation
Power calculation

Mathematical constant:

static double E;     //Base of natural logarithm: e
static double PI;    //PI: Pi

common method
Seeking random numbers

static double random();   //Returns a double value greater than or equal to 0.0 and less than 1.0.

Absolute value

static double abs(double a);
static float abs(float a);
static int abs(int a);
static long abs(long a);

Maximum value

static double max(double a, double b);

static float max(float a, float b);
static int max(int a, int b);
static long max(long a, long b)
```;

//Minimum value
static double min(double a, double b);
static float min(float a, float b);
static int  min(int a, int b);
static long min(long a, long b);

Rounding

static double ceil(double a);     //Round up: returns the minimum integer value greater than or equal to the parameter.
static double floor(double a);    //Round down: returns the maximum integer value less than or equal to the parameter.

Rounding

static long round(double a);
static int round(float a);

Nearest integer

static double rint(double a);    //Returns the integer closest to the parameter.

Trigonometric calculation

static double sin(double a);     //Sine function
static double cos(double a);     //cosine function
static double tan(double a);     //Tangent function
static double sinh(double x);    //Hyperbolic sine function
static double cosh(double x);    //Hyperbolic cosine function
static double tanh(double x);    //Hyperbolic tangent function

Inverse trigonometry

static double acos(double a);   //The arccosine function returns an angle in the range of 0.0 to pi.
static double asin(double a);   //Anti sine function; the angle returned is in the range of - pi/2 to pi/2.
static double atan(double a);   //Arctangent function; the angle returned is in the range of - pi/2 to pi/2.

Square root calculation

****static double sqrt(double a);    //Square root.
static double cbrt(double a);    //Cube root.
static double hypot(double x, double y);    //Returns sqrt (x^2 + y^2). * *

Logarithmic calculation

static double log(double a);      //The logarithm based on the natural constant e.
static double log10(double a);    //Base 10 logarithm.
static double log1p(double x);    //Returns the natural logarithm of x+1.

Power calculation

static double pow(double a, double b);    //Power function: returns the b power of a.
static double exp(double a);    //Returns the parameter power of the natural base e.
static double expm1(double x);    //Return exp(x)-1

Angle conversion

static double toRadians(double angdeg);    //Converts an angle in degrees to an approximate equivalent angle measured in radians.
static double toDegrees(double angrad);   //Converts the angle measured in radians to an approximate equivalent angle measured in degrees.

Tags: Java less

Posted on Sat, 14 Mar 2020 11:01:36 -0400 by Imothep