Java专题 Math类的使用以及方法总结

	//Math
	Math.abs(123);					//取绝对值
	Math.cbrt(8);					//开立方根
	Math.sqrt(9);					//开平方根 正的
	Math.ceil(4.6);					//向上取整
	Math.floor(4.6);				//向下取整
	Math.log10(100);				//求以10为底的对数
	Math.max(3, 5);					//求最大值
	Math.min(2, 78);				//最小值
	Math.pow(2, 7);					//2的7次方
	Math.random();					//随机一个数 0-1之间 要改变界线直接乘最大值
	Math.round(5.5);				//四舍五入
	Math.round(5.4);
	
	//更多查看API文档或自动提示
	
	//随机函数类
	Random random = new Random();
	int i = random.nextInt(2)+1;		//界限 不加1为0-1   加了1为1-2
										//若要20-40则界限选20,再加20
	System.out.println(i);

格外补充案例

	System.out.println(Math.E);				//Math
	System.out.println(Math.PI);
	System.out.println(Math.abs(-3.2));
	System.out.println(Math.cbrt(8));			//开立方
	System.out.println(Math.sqrt(9));			//开正平方
	System.out.println(Math.ceil(3.3));			//向上取证整
	System.out.println(Math.floor(3.3));		//向下取整
	System.out.println(Math.log10(100));		//10为底求100的对数
	System.out.println(Math.max(23, 2.44));
	System.out.println(Math.pow(2, 3));			//求幂
	System.out.println(Math.round(3.6));		//四舍五入
	System.out.println(Math.round(3.3));
	System.out.println(Math.random());
	System.out.println(Math.tan());

三角函数,一般数学计算均可在Math中提示出现,但需要对数值结果做处理。

有待更新

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值