zoukankan      html  css  js  c++  java
  • java-number2

    abs() :该方法给出了参数的绝对值,参数可以是int,float,long,double,short,byte

    Syntax
    double abs(double d)
    float abs(float f)
    int abs(int i)
    long abs(long lng)
    
    public class Test { 
    
       public static void main(String args[]) {
          Integer a = -8;
          double d = -100;
          float f = -90;
    
          System.out.println(Math.abs(a));
          System.out.println(Math.abs(d));     
          System.out.println(Math.abs(f));    
       }
    }
    
    


    ceil():该方法给出大于或等于参数的最小整数

    Syntax
    double ceil(double d)
    double ceil(float f)
    
    public class Test { 
    
       public static void main(String args[]) {
          double d = -100.675;
          float f = -90;    
    
          System.out.println(Math.ceil(d));
          System.out.println(Math.ceil(f)); 
    
          System.out.println(Math.floor(d));
          System.out.println(Math.floor(f)); 
       }
    }
    


    floor() 该方法给出小于或等于参数的最大整数

    Syntax
    double floor(double d)
    double floor(float f)
    
    public class Test { 
    
       public static void main(String args[]) {
          double d = -100.675;
          float f = -90;
    
          System.out.println(Math.floor(d));
          System.out.println(Math.floor(f)); 
    
          System.out.println(Math.ceil(d));
          System.out.println(Math.ceil(f));
       }
    }
    


    rint():返回值最接近参数的整数

    Syntax
    double rint(double d)
    
    public class Test {
    
       public static void main(String args[]) {
          double d = 100.675;
          double e = 100.500;
          double f = 100.200;
    
          System.out.println(Math.rint(d));
          System.out.println(Math.rint(e)); 
          System.out.println(Math.rint(f)); 
       }
    }
    


    round():返回最接近的long或int

    Syntax
    This method has the following variants −
    
    long round(double d)
    int round(float f)
    
    public class Test { 
    
       public static void main(String args[]) {
          double d = 100.675;
          double e = 100.500;
          float f = 100;
          float g = 90f;
    
          System.out.println(Math.round(d));
          System.out.println(Math.round(e)); 
          System.out.println(Math.round(f)); 
          System.out.println(Math.round(g)); 
       }
    }
    


    min():给出两个参数的最小值,参数可以是int,float,long,double

    Syntax
    This method has the following variants −
    
    double min(double arg1, double arg2)
    float min(float arg1, float arg2)
    int min(int arg1, int arg2)
    long min(long arg1, long arg2)
    
    public class Test {
    
       public static void main(String args[]) {
          System.out.println(Math.min(12.123, 12.456));      
          System.out.println(Math.min(23.12, 23.0));  
       }
    }
    
    
    


    max() 给出两个参数最大值,参数可以是int,float,long,double

    Syntax
    This method has the following variants −
    
    double max(double arg1, double arg2)
    float max(float arg1, float arg2)
    int max(int arg1, int arg2)
    long max(long arg1, long arg2)
    
    public class Test { 
    
       public static void main(String args[]) {
          System.out.println(Math.max(12.123, 12.456));      
          System.out.println(Math.max(23.12, 23.0));  
       }
    }
    ![](https://images2018.cnblogs.com/blog/1202026/201806/1202026-20180606230843119-1176811323.png)
    
    

    pow():返回第一个参数基于第二参数次方的值

    public class Test { 
    
       public static void main(String args[]) {
          double x = 11.635;
          double y = 2.76;
    
          System.out.printf("The value of e is %.4f%n", Math.E);
          System.out.printf("pow(%.3f, %.3f) is %.3f%n", x, y, Math.pow(x, y));
       }
    }
    
    


    Math.sqrt() 平方根
    Math.sin()
    Math.cos()
    Math.tan()
    ....
    Math.random() 产生一个0到1的随机数

  • 相关阅读:
    急招.NET系列职位
    程序员成长的三个方法
    xwebkitspeech
    张小龙的产品
    浅析商业银行“业务连续性管理体系”的构建
    Sonar for dotNet
    Moles测试Contrustor时候遇到的一个问题
    EntityFramework 用Moles的mock
    Accessor中Generic的元素是internal/private的会导致转换失败的异常
    Android自用Intent 介绍
  • 原文地址:https://www.cnblogs.com/cyany/p/9147964.html
Copyright © 2011-2022 走看看