美文网首页
Java基础方法6(Math类)

Java基础方法6(Math类)

作者: 页川叶川 | 来源:发表于2019-03-25 23:21 被阅读0次

    9.2.Math类

    public static void main(String[] args) {
            //三角函数方法
        System.out.println("90度的正弦值:"+Math.sin(Math.PI/2));
        System.out.println("0度的余弦值:"+Math.cos(0));
        System.out.println("60度的正切值:"+Math.tan(Math.PI/3));
        System.out.println("2的平方根与2商的反正值:"+Math.asin(Math.sqrt(2)/2));
        System.out.println("2的平方根与2商的反余值:"+Math.asin(Math.sqrt(2)/2));
        System.out.println("1的反正切值:"+Math.atan(1));
        System.out.println("120度的弧度值:"+Math.toRadians(120.0));
        System.out.println("PI/2的角度值:"+Math.toDegrees(Math.PI/2));
            
        //指数函数方法
        System.out.println("e的平方值:"+Math.exp(2));
        System.out.println("以e为底2的对数值:"+Math.log(2));
        System.out.println("以10为底2的对数值:"+Math.log10(2));
        System.out.println("4的平方根值:"+Math.sqrt(4));
        System.out.println("8的立方根值:"+Math.cbrt(8));
        System.out.println("2的2次方值:"+Math.pow(2, 2));
    }
    
    public static void main(String[] args) {
            //取整函数方法
            System.out.println("使用ceil()方法取整:"+Math.ceil(5.2));
    //返回第一个大于等于参数的整数
            System.out.println("使用floor()方法取整:"+Math.floor(2.5));
    //返回第一个小于等于参数的整数
            System.out.println("使用rint()方法取整:"+Math.rint(2.7));
    //返回与参数最接近的整数
            System.out.println("使用rint()方法取整:"+Math.rint(2.5));
    //返回与参数最接近的整数
            System.out.println("使用round()方法取整:"+Math.round(3.4f));
    //将参数加上0.5后返回最接近的整数
            //将参数加上0.5后返回最接近的整数,并将结果强制转换为长整型
            System.out.println("使用round()方法取整:"+Math.round(2.5));
    
            //取最大值、最小值、绝对值函数方法
            System.out.println("4和8的较大者:"+Math.max(4,8));
            System.out.println("4.4和4较小者:"+Math.min(4.4,4));
            System.out.println("-7的绝对值:"+Math.abs(-7));
        }
    

    文集推荐:

    Java基础方法集1
    Python基础知识完整版
    Spring Boot学习笔记
    Linux指令进阶
    Java高并发编程
    SpringMVC基础知识进阶
    Mysql基础知识完整版
    健康管理系统学习花絮(学习记录)
    Node.js基础知识(随手笔记)
    MongoDB基础知识
    Dubbo学习笔记
    Vue学习笔记(随手笔记)

    声明:发表此文是出于传递更多信息之目的。若有来源标注错误或侵犯了您的合法权益,请作者持权属证明与本我们(QQ:981086665;邮箱:981086665@qq.com)联系联系,我们将及时更正、删除,谢谢。

    相关文章

      网友评论

          本文标题:Java基础方法6(Math类)

          本文链接:https://www.haomeiwen.com/subject/sdoivqtx.html