Java中Math类的常用方法

Math类常用方法
静态字段:

static double E:比任何其他值都接近e(即自然对数的底数)的double值。

static double PI:比任何其他值都接近pi的double值。

方法:

static double abs(int||double||folat||long a):返回对应类型值的绝对值。

static double ceil(double a):向上取整。

static double floor(double a):向下取整。

static long round(double a):返回最接近参数的long值。

static int round(float a):返回最接近参数的int值。

static float/int/double/long max(float||... a,float||... b):返回两个参数中较大的一个。

static float/int/double/long min(float||... a,float||... b):返回两个参数中较小的一个。

static double random():随机返回带正号的double值,该值大于0.0小于1.0.

public static void main(String[] args) {
		//	Math.E自然对数
		System.out.println(Math.E);
		
		//	int类型的运算结果继续为int
		System.out.println(1 / 2);
		
		//	圆周率
		System.out.println(Math.PI);
		
		//	Math.round(number)对给定的number进行四舍五入
		System.out.println(Math.round(-10.4));
		
		//	Math.floor(number)对number向下取整
		System.out.println(Math.floor(10.9));
		
		//	Math.ceil(number)对于number向上取整
		System.out.println(Math.ceil(10.1));
		
		//	Math.sqrt(number)对number进行求平方根
		System.out.println(Math.sqrt(9));
		
		//	Math.pow(n1, n2)求n1的n2次方
		System.out.println(Math.pow(2, 3));
		
		//	Math.sin(number)求number的正弦值
		System.out.println(Math.sin(Math.PI / 2));
	}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值