Use of Math tools

1. Package: java.lang package does not need to guide

 

2.Math method of performing basic arithmetic operations class contains, ever other exponential, logarithmic, trigonometric functions and square root.

Features: methods in this class are static, so you can directly use the class name method name (argument) call.

 

3. Common member method:

static double public ABS (double A) : Returns the absolute double value.

 

Double static public ceil (Double A) : returns the smallest integer greater than or equal parameters.

 

Double static public Floor (Double A) : returns the largest integer less than or equal parameters.

 

static long public round (Double A) : Returns the closest long argument. (Corresponding to the rounding method)

 

public  static int max (int A, B int):  returns two values int larger one.

 

public  static int min (int A, B int):  Returns the value of one of the two smaller int.

 

Integrated Case

Calculated -10.8to 5.9between an absolute value greater than 6or less than 2.1an integer of the number of?

 

public  class MathTest {
   public  static  void main (String [] args) {
     // definition of minimum 
    Double min = -10.8 ;
     // maximum value defined 
    Double max = 5.9 ;
     // custom variable count 
    int COUNT = 0 ;
     // the range cycle 
    for ( Double I = Math.ceil (min); I <= max; I ++ ) {
       // Get and determines an absolute value of 
      IF (the Math.abs (I)> || the Math.abs. 6 (I) <2.1 ) {
         // count 
        cOUNT ++ ; 
      } 
    }
    System.out.println ( "Number is:" + count + "a" ); 
  } 
}

 

Guess you like

Origin www.cnblogs.com/libinhong/p/10990130.html