The methods provided by the Java.lang.Math class are static, and " static ingestion " makes it unnecessary to write the class name before the method every time the class method is called:
import static java.lang.math.*;
This allows you to simply write the method name when you call the math method, such as:
cos (radians);
----------------------------------------------------------
1, the Basic method:
ABS, Max, Min, ceil, floor, rint, round
Heavy-duty ABS method that returns the absolute value of a number (int, long, float, double)
Overloads Max and Min methods, returns the maximum and minimum values for two numbers (int, long, float, double)
public static double Ceil (double x); Rounding up, returns double
public static double floor (double x); Rounding down, returns double
public static double rint (double x); Returns the nearest integer to x as a double value, assuming an equal distance from x to two integers, returning an even number
public static long round (double x); Returns (long) Math.floor (x+0.5);
public static int round (float x); Returns (int) Math.floor (x+0.5);
2. Exponential and Logarithmic methods:
(MATH.E = 2.7183)
Exp, log, pow, sqrt
3. Trigonometric functions:
Sin, cos, tan, ASIN, ACOS, Atan
Double atan2(double y, double x); The coordinates of the Cartesian coordinate system (x, Y) are converted to coordinates in the polar coordinates (R, Theta), and the angle is returned Thera
public static double Todegrees (double radians);
public static double Toradians (double degree);
4. Random number
0.0 <= Math.random () < 1.0
Suppose you want to get a random integer between [0, 10]:
int number = (int) (Math.random () * 10);
Suppose you want to get a random integer between [50, 100]:
int number = + (int) (Math.random () * 50);
Suppose you want to get a random integer between (A, a+b]:
int number = a + (int) (Math.random () * b);
You can use Math.random () to get a single random number, but to get a series of random numbers, you can use the Java.util.Random class to invoke the corresponding method implementation by creating an object.
The basic method in Java.lang.Math