The math class contains the methods required to complete the basic mathematical functions. These methods can be divided into three types: trigonometric functions, exponential function methods and service methods. The PI and e two double constants are defined in the math class.
Pi is the value of π, and E is the value of the e index bottom, respectively: 3.141592653589793 and 2.718281828459045;
The Math class contains the following trigonometric function methods:
- Math.todegrees This method converts the Radian value between-Π/2 to π/2 into degrees, for example: Math.todegrees (MATH.PI/2) result is 90.0;
- Math.toradians This method is to convert degrees to radians between-Π/2 and Π/2, for example: Math.toradians (30) results are Π/6;
- The three methods of Math.sin, Math.Cos and Math.tan are sine and cosine and tangent in trigonometric functions, whereas Math.asin, Math.acos and Math.atan are their inverse functions;
- exponential function method
There are five methods in the Math class that are related to exponential functions math.exp (a) method mainly obtains the value with the base of e as exponent; Math.log () and MATH.LOG10 () are logarithmic functions; Math.pow (A, A, b) is a value of the bottom ; Math.sqrt () is a radical.
The math class contains five rounding methods: The Math.ceil () method is to take a value to Dali, Math.floor () method is to take the value of the small inside, Math.rint () method is rounding method to take value, The Math.Round method is divided into two types of int and long, and Math.Round (a) is Math.floor (a+0.5).
I don't explain these three ways, they are the maximum and the minimum and the absolute value.
The generation of random number values ranges from 0.0 to 1.0 for double type values. You can also use simple expressions to generate random numbers of any range, for example: (int) (Math.random () *10) returns a random integer from 0 to 9.
Like Java programming Children's shoes, No.: Mjx_ java. Can pay attention to this platform, mainly to explain some good Java in the blog and information, in an update every day, we take a look at the car when the time to take a look at the car, can pass the time, but also to increase their Java knowledge, but also hope that we can communicate more in the platform, the increase in knowledge from the Exchange, If you have a good blog post or write your own article can also be sent to small, let the small part of the publication, will be labeled on the sender's name.
An explanation of the math class in Java