Math类

 

public class MathTest {
    public static void main(String[] args) {
        //三角函数
        System.out.println(Math.sin(2));
        System.out.println(Math.cos(2));
        System.out.println(Math.tan(2));
        System.out.println(Math.asin(0.5));
        System.out.println(Math.acos(0.5));
        System.out.println(Math.atan(0.5));
        System.out.println(Math.toRadians(50));//将角度转换为弧度为单位的近似等效角度
        System.out.println(Math.toDegrees(0.8726646259971648));//将以弧度测量的角度转换为以度测量的近似等效角度
    }
}

结果:

0.9092974268256817
-0.4161468365471424
-2.185039863261519
0.5235987755982989
1.0471975511965979
0.4636476090008061
0.8726646259971648
50.0
public class MathTest {
    public static void main(String[] args) {
        System.out.println(Math.exp(2));//返回:e^a的值,其中e是自然对数的底。
        System.out.println(Math.log(10));//返回ln(a)
        System.out.println(Math.log10(10));
        System.out.println(Math.sqrt(4));//平方根
        System.out.println(Math.cbrt(8));//立方根
    }
}

结果:

7.38905609893065
2.302585092994046
1.0
2.0
2.0
public class MathTest {
    public static void main(String[] args) {
        System.out.println(Math.IEEEremainder(5, 2));//5/2的余数
        System.out.println(Math.ceil(6.2));//返回大于这个数的最小整数
        System.out.println(Math.floor(6.2));//返回小于这个数的最小整数
        System.out.println(Math.rint(6.2));
        System.out.println(Math.rint(6.7));//返回最接近这个数的整数
        System.out.println(Math.pow(2, 3));//2^3
        System.out.println(Math.round(3.2));
        System.out.println(Math.round(3.8));//返回接近这个数的整型值
        System.out.println(Math.random());//返回大于0小于1的伪随机数
        System.out.println(Math.addExact(2, 3));//返回其参数的总和
        System.out.println(Math.subtractExact(4, 2));//两数相减
        System.out.println(Math.multiplyExact(2, 5));//两数相乘
        System.out.println(Math.incrementExact(3));//加1
        System.out.println(Math.decrementExact(2));//减1
        System.out.println(Math.negateExact(3));//求相反数
        System.out.println(Math.toIntExact(-4));//返回long参数的值;如果值溢出int类型,则抛出异常
        System.out.println(Math.abs(-2));//绝对值
        System.out.println(Math.max(3, 5));
        System.out.println(Math.min(3, 2));//返回最大最小值
    }
}

结果:

1.0
7.0
6.0
6.0
7.0
8.0
3
4
0.7131722725644338
5
2
10
4
1
-3
-4
2

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值