java.Math类方法

java.lang.Math类方法
1.Math.max 求两数中最大/Math.min 求两数中最小
package Test0228;
public class Test007 {public static void main(String[] args) {
double x=12.45,y=52.4; System.out.println(Math.max(x, y)); System.out.println(x<y?x:y);}}
2.Math.round 四舍五入返回int型或者long型
package Test0228;
public class Test008 { public static void main(String[] args) {
double x = 12.56;
double y= 125.69;
double w=12.1; System.out.println(Math.round(x)); System.out.println(Math.round(y)); System.out.println(Math.round(w));
}}
3.Math.abs 求绝对值,典型使用场景就是浮点
数的等值判定问题
package Test0228;
public class Test0001 {public static void main(String[] args) {
double res = 0;
for (int i=0;i<10;i++) {
res+=0.1;
}
if(Math.abs(1-res)<1e-6) { System.out.println(“计算结果为:”);
}else
System.out.println(“结果为:”+res);}}
1e-6,其中e可以大写,也可以小写,这是浮点数中的科学计数法,表示1*10-6
三角函数
Math.sin 正弦函数 Math.asin 反正弦函数Math.cos 余弦函数 Math.acos 反余弦函数Math.tan 正切函数 Math.atan 反正切函数Math.toDegrees 弧度转化为角度 Math.toRadians 角度转化为弧度
指数计算
Math.sqrt 求开方 Math.sqrt(4)Math.pow 求某数的任意次方, 抛出ArithmeticException处理溢出异常Math.exp 求e的任意次方Math.log10 以10为底的对数Math.log 自然对数

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值