Java中,Math类的常用方法

数学类 Math
常用的方法:

  • abs(参数) 绝对值
  • acos(参数)、asin、atan、cos、sin、tan 三角函数
  • sqrt(参数) 平方根
  • pow(double a,double b) a的b的次幂
  • log(参数) 自然对数
  • exp e为底的指数
  • max(double a,double b) a、b中的最大值
  • min(double a,double b) a、b中的最小值
  • random() 返回0.0到1.0的随机数
  • random().nextInt(n) 返回[0,n)的随机数
  • long round(double a) double型的数据a转换成long型数据(四舍五入)
  • toDegrees(double angrad) 弧度 转化成 角度
  • toRadians(double angdeg) 角度 转化成 弧度

代码举例:

public class MathTest {
	public static void main(String[] args) {
		double a=-3.14;
		System.out.println(a+"的绝对值:"+Math.abs(a));
		
		int b =4;
		System.out.println(b+"的平方根:"+Math.sqrt(b));
		System.out.println(b+"的2的次幂:"+Math.pow(b,2));
		
		double c= 3.15;
		double d= 4.5;
		System.out.println(c+"和"+b+"之间的最大值:"+Math.max(c, d));
		
	}
}

结果:
在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值