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
        }
    }
  • 相关阅读:
    WPF中样式中事件处理
    模板方法
    WPF 中ComboBox绑定DataSet
    装饰模式
    【转帖】c#项目的打包部署教材图文
    WPF中用比例设置长度或宽度
    在WFP中完美使用winform的控件
    一个WPF软件作品新鲜出炉,欢迎拍砖
    建造者模式(生成器模式)
    Windows Presentation Foundation 中的 Pack URI
  • 原文地址:https://www.cnblogs.com/xulinjun/p/14769707.html
Copyright © 2011-2022 走看看