In view of Java's desire to die, finishing the usual math is as follows:
1:java rounding
A:floor Downward rounding
Usage: Math.floor (num)
Math.floor (1.9)//1 Math.floor (-1.9)//-2
B:round rounding
Usage: math.round (num) is actually equivalent to Math.floor (num+0.5)
Math.Round (1.5)//2 Math.Round (1.4)//1
Math.Round ( -1.4)//-1 Math.Round ( -1.5)//-1 Math.Round (-1.6)//-2
C:ceil the smallest integer not less than num
Usage: Math.ceil (num)
Math.ceil (1.4)//2 Math.ceil (1.5)//2 Math.ceil (1.6)//2
Math.ceil ( -1.4)//-1 Math.ceil ( -1.5)//-1 Math.ceil (-1.6)//-1
D: Divine method direct plus (int) cast, directly remove the decimal point, no upward downward, the best way to use when needed
2:java Absolute Value
Math.Abs (num)
Math.Abs (-30.5)//30.5
3:java Random Number
Math.random () Number of random 0~1
(int) (100*math.random ()) so you can take 0~100 random integers
4:java Power function
Math.pow (A, B) a the second party
Math.pow (x,2) is the square
Math.pow (x,3) is the cubic
5:java Open Radicals
MATH.SQRT (num) num's square root
Common methods for math in Java