JAVA [MATH]

本文详细介绍了Java中Math类的各种数学运算方法,包括指数、对数、取整等操作,并通过实例展示了这些方法的具体使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

     /**
     * java.lang.Math
     */

    public static void MathTest(){

       

        System.out.println(Math.class);

        System.out.println(Math.PI);
        
        System.out.println(Math.E);
        System.out.println(Math.exp(1));         //e 的 double 次幂
        System.out.println(Math.exp(2));        
        System.out.println(Math.expm1(2));         //ex -1
        // 返回 double 值的自然对数(底数是 e)
        System.out.println(Math.log(7.38905609893065));  
        // 返回 double 值的底数为 10 的对数
        System.out.println(Math.log10(100));     
        //对于小的 x 值,log1p(x) 的结果比 log(1.0+x) 的浮点计算结果更接近 ln(1 + x) 的实际结果
        System.out.println(Math.log1p(0.00456));
        
        System.out.println(Math.abs(-10));
        System.out.println(Math.cbrt(27));       // 27的立方根3
        System.out.println(Math.PI);

        
        //
        //该值大于等于参数
        System.out.println(Math.ceil(10.5));     
        System.out.println(Math.ceil(-12.3));    
        //小于等于参数
        System.out.println(Math.floor(10.4));    
        System.out.println(Math.floor(-11.3));
        //返回最接近参数并等于某一整数的 double 值
        System.out.println(Math.rint(563.4));   
        System.out.println(Math.rint(563.5));  
        System.out.println(Math.rint(-563.5));
        //返回最接近参数并等于某一整数的 long 值
        System.out.println(Math.round(563.4));   
        System.out.println(Math.round(563.5));  
        System.out.println(Math.round(-563.5));
        //如果参数为 0,则返回 0;如果参数大于 0,则返回 1.0;如果参数小于 0,则返回 -1.0
        System.out.println(Math.signum(-11.3));  
        System.out.println(Math.signum(0));  
        System.out.println(Math.signum(11));  
        
        
        //比较大小
        System.out.println(Math.max(123563.45, -5641014));
        System.out.println(Math.max(456, -2));
        System.out.println(Math.min(123563.45, -5641014));
        System.out.println(Math.min(456, -2));

        
        //  返回第一个参数的第二个参数次幂的值
        System.out.println(Math.pow(456, -2));   
        System.out.println(Math.sqrt(8956));   
        
        //a*2^b
//        System.out.println(Math.scalb(a, b));  
        
        
        //带正号的 double 值,该值大于等于 0.0 且小于 1.0
        System.out.println(Math.random());  

    }


**********************************************************************************************

class java.lang.Math
3.141592653589793
2.718281828459045
2.7182818284590455
7.38905609893065
6.38905609893065
2.0
2.0
0.004549634698571382
10
3.0
3.141592653589793
11.0
-12.0
10.0
-12.0
563.0
564.0
-564.0
563
564
-563
-1.0
0.0
1.0
123563.45
456
-5641014.0
-2
4.809172052939366E-6
94.63614531456784
0.6853638229064377


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值