zoukankan      html  css  js  c++  java
  • Java——Math

    一、介绍

    Math包含执行基本数字运算的方法,如基本指数、对数、平方根和三角函数。所提供的都是静态方法,可以直接调用。

    二、abs

    public static int abs(int a)
    

    abs方法用来获取参数a的绝对值

    例子

    public class MathTest {
        public static void main(String[] args) {
            int a = Math.abs(-6);
            int b = Math.abs(7);
            System.out.println(a);   // 6
            System.out.println(b);   // 7
        }
    }
    

    三、ceil

    public static double ceil(double a)

    ceil方法用来向上取整

    例子

    public class MathTest {
        public static void main(String[] args) {
            double a = Math.ceil(6.001);
            System.out.println(a);   // 7.0
        }
    }

    四、floor

    public static double floor(double a)
    

    floor方法用来向下取整

    例子

    public class MathTest {
        public static void main(String[] args) {
            double a = Math.floor(6.999);
            System.out.println(a);   // 6.0
        }
    }
    

    五、pow

    public static double pow(double a, double b)
    

    pow方法用来获取a的b次幂

    例子

    public class MathTest {
        public static void main(String[] args) {
            int a = 2, b = 3;
            System.out.println(Math.pow(a, b));   // 8.0
        }
    }
    

    六、round

    public static long round(double a)
    

    round方法用来四舍五入取整

    例子

    public class MathTest {
        public static void main(String[] args) {
            double a = Math.round(6.499);
            double b = Math.round(6.5);
            System.out.println(a);   // 6.0
            System.out.println(b);   // 7.0
        }
    }
  • 相关阅读:
    laravel 查询
    好友数量
    laravel 更新
    laravel 多对多关联 attach detach sync
    laravel zh-CN
    laravel 框架后台主菜单接口
    Visual Studio 2012 Update 3
    IIS7 禁止目录运行脚本
    [驱动力]读书笔记
    [Python Essential Reference, Fourth Edition (2009)]读书笔记
  • 原文地址:https://www.cnblogs.com/xulinjun/p/14769707.html
Copyright © 2011-2022 走看看