Math related classes Math

Outline

java.lang.Math class contains methods for performing basic mathematical operations, like ever exponential, logarithmic, trigonometric functions and square root. Tools like these classes, all of its methods are static methods, and does not create an object, call up is very simple.

Common method

  • public static double abs (double a): Returns the absolute double value.
  • public static double ceil (double a): returns the smallest integer greater than or equal parameters.
  • public static double floor (double a): returns the largest integer less than or equal parameters.
  • public static long round (double a): Returns the closest long argument. (Corresponding to the rounding method)
demand
Calculating integer between -10.8 to 5.9, the absolute value of greater than 6 or less than 2.1 the number of?
Package Demo03; 

public  class Demo01 {
     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 ;
         / / within a range of circulating 
        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 + "th") // Number is: 9 

    } 
}

 

Guess you like

Origin www.cnblogs.com/wurengen/p/10962698.html