• 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的随机数

  • 相关阅读:
    HTTP的KeepAlive是开启还是关闭?
    JS中关于in运算符的问题
    关于jQuery的inArray 方法介绍
    JS中括号的用法
    关于js中for in的缺陷浅析
    Ajax datatype:'JSON'的error问题Status1:200,JSON格式
    windows 如何查看端口占用情况?
    确认过眼神,看清 HTTP 协议
    高考完?入门级的开源项目带你开启编程之旅
    MongoDB入门系列(四):权限管理
  • 原文地址:https://www.cnblogs.com/cyany/p/9147964.html
Copyright © 2020-2023  润新知