栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

JAVA APl基础类库---Math数学类

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

JAVA APl基础类库---Math数学类

一.Object类(根类||先祖类):所有类的父类,为子类提供对对象操作的基本功能。

        Class<泛型> getClass():返回对象所属的类;返回类型Class。

二.Math类 (数学类)

public static void main(String[] args) {
        System.out.println(Math.E);//2.718281828459045(数学常量e)
        System.out.println(Math.PI);//3.141592653589793(圆周率)
        System.out.println(Math.abs(-1)+" "+Math.abs(-2.1));//1 2.1 返回绝对值
        System.out.println(Math.random());//返回0-1之间的随机数
        System.out.println((int)(Math.random()*10));//返回0-10间的随机数
        System.out.println(Math.pow(2,6));//64.0返回2的6次方
        System.out.println(Math.sqrt(8));//开平方
        System.out.println(Math.cbrt(8));//开立方
        System.out.println(Math.max(2,3));//3 返回大值
        System.out.println(Math.min(2,3));//2 返回最小值
        System.out.println(Math.ceil(7.1));//8 向上取整
        System.out.println(Math.floor(7.9));//7 向下取整
        System.out.println(Math.round(2.501));//3 四舍五入
    }

Math为最终类,其方法都是静态方法,通过类名调用,其中部分方法有着多种类型的的重载方法

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/782223.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号