Math: The class used to perform mathematical operations.
Member Methods:
public static int abs (int a)//absolute value
public static double Ceil (double A)//want to go up and take the whole
public static double floor (double A)//down rounding
public static int max (int a,int b)//Take maximum value
public static Double pow (double a,double b)//a B-square
public static double random ()//
public static int round (float a) argument is double for self-study
1 //public static int abs (int a), take absolute value2System.out.println (Math.Abs (100));3System.out.println (Math.Abs (-100));4 5 //Public static Double Ceil (double A), rounding up6System.out.println (Math.ceil (12.3));7System.out.println (Math.ceil (12.7));8System.out.println (Math.ceil (12.0));9 Ten //Public static Double floor (double a), rounded down OneSystem.out.println (Math.floor (12.3)); ASystem.out.println (Math.floor (12.7)); -System.out.println (Math.floor (12.0)); - the //public static int max (int a,int b) min Self-study -System.out.println (Math.max (2, 3)); - //determine the maximum value of a 2,3,4 -System.out.println (Math.max (Math.max (2, 3), 4)); + //If multiple numbers are the maximum value: - //1. Create an array, store the data in an array, and then use For+if to remove the maximum value + //2. Bubble sort, remove last value A //3.arrays.sort (int[] arr), remove the last at - //Public static Double pow (double a,double b) A B-square -System.out.println (Math.pow (2, 3)); - -System.out.println ("---------------"); - in //Public static Double random (), resulting in a random number between 0-1, including 0 including 1 - System.out.println (Math.random ()); to //requirement: Generates a random number between 1-100 + intRadom = (int) (Math.random () *100+1); - System.out.println (Radom); the * //public static int round (float a), rounded $System.out.println (Math.Round (12.4));Panax NotoginsengSystem.out.println (Math.Round (12.6));Member Method Demo
The results of the operation are as follows:
100
100
13.0
13.0
12.0
12.0
12.0
12.0
3
4
8.0
---------------
0.7210652393976311
75
12
13
Java Learning: Math class