疯狂java讲义第七章补充习题第8题答案

8、使用Math类的各种方法,
变量
E
PI
方法
abs()
absExact()找不到这个方法,可能已经移除了,
acos()
addExact()
asin()
atan()
atan2()
cbrt()
ceil()
copySign()
cos()
cosh()
decrementExact() 自减 相当于 – 不过只适用于int和long类型
exp()
expm1()
floor()
floorDiv() 对于整数而不是浮点数来说,除的结果是直接截去尾数的,所以除的结果如果是正数会有一种floor()的效果,而如果除的结果是负数则会有一种ceil()的效果,而floorDiv()就是把负数也变成floor()的效果
floorMod()我也不知道为什么会这样的结果,奇怪?
fma() 返回a*b +c
getExponent()
hypot()勾股定理
incrementExact() 自加 相当于++ 不过只适用于int和long类型
log() 以e为底,其实是ln
log10() 以10为底
log1p() 以e为底,参数+1
max()
min()
multiplyExact() 只适用于int和long
multiplyFull()
multiplyHigh()先放着,没看懂是怎么用,不知道是从来干什么的
negateExact() 就是-
nextAfter() 看不懂,先放着
nextDown() IEEE754的浮点数其实可以说是离散的,有些值,无法用IEEE954表示,比如0.3,所以nextDown() 就是返回距离最近,但值比参数更小的浮点数
nextUp() 同上,返回的是距离最近,但是值比参数更大的浮点数
pow()
random()
rint() 0.5 被放在朝中间的方向变化上和0.4、0.3这些一样
round() 四舍五入
scalb()
signum()
sin()
sinh()
sqrt()
subtractExact()
tan()
tanh()
toDegrees() 暂时没懂这个弧度是怎么转换成角度的,以后知道了再补充
toIntExact()
toRadians()
ulp() 没看懂,先放着

import java.util.*;
import java.io.*;
public class Test
{
	public static void main(String[] args) throws CloneNotSupportedException
	{
		//Math
		//变量
		System.out.println(Math.E);
		System.out.println(Math.PI);
		
		//方法
		System.out.println(Math.abs(-10));
		/*
		System.out.println(Math.absExact(10));
		System.out.println(Math.absExact(Integer.MAX_VALUE));
		System.out.println(Math.absExact(Integer.MIN_VALUE));
		*/
		System.out.println(Math.acos(0.5));
		System.out.println(Math.addExact(10,20));
		System.out.println(Math.asin(0.5));
		show(Math.atan(0.5));
		show(Math.atan2(0.5,0.7));
		show(Math.cbrt(2));
		show(Math.ceil(0.2));
		show(Math.copySign(2,-10));
		show(Math.copySign(-2, 10));

		show(Math.cos(0.5));
		show(Math.cosh(0.5));

		show(Math.decrementExact(10));

		show(Math.exp(2));
		show(Math.expm1(2));

		show(Math.floor(0.5));

		show(Math.floorDiv(4,3));
		show(Math.floorDiv(-4,3));
		show(-4/3);
		
		show(-4 % 3);
		show(Math.floorMod(-4,3));
		
		show(Math.fma(2,2,3));

		show(Math.getExponent(10.0));
		show(Math.exp(2));

		show(Math.hypot(3,4));

		show(Math.IEEEremainder(10,3));

		show(Math.incrementExact(2));

		show(Math.log(3));
		show(Math.log10(3));
		show(Math.log1p(3));

		show(Math.max(1,10));
		show(Math.min(1,10));

		show(Math.multiplyExact(2,10));
		show(Math.multiplyFull(2,10));
		//show(Math.multiplyHigh(0x12300000000,10L));

		show(Math.negateExact(-10));
		show(Math.negateExact(10));

		show(Math.nextAfter(10,2));
		show(Math.nextAfter(10,-2));
		show(Math.nextDown(10));
		show(Math.nextUp(10));

		show(Math.pow(2,2));

		show(Math.random());
		show(Math.rint(-0.5));
		show(Math.rint(-0.6));

		show(Math.round(0.4));
		show(Math.round(0.46));

		show(Math.scalb(2,2));
		show(Math.signum(10));
		show(Math.signum(-10));

		show(Math.sin(3));
		show(Math.sinh(3));

		show(Math.sqrt(4));
		show(Math.subtractExact(2,2));
		
		show(Math.tan(10));
		show(Math.tanh(10));
		
		show(Math.toDegrees(0.5));
		
		show(Math.toIntExact(10));

		show(Math.toRadians(30));

		show(Math.ulp(2));
		show(Math.ulp(3));
		
	}
	public static void show(double n)
	{
		System.out.println(n);
	}
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

细水长流cpu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值