Math类是一个最终类,不能被继承,里面的所有方法都是static方法,不需要被new ,都是工具方法
常用API
package com.woniuxy.java17.study;
public class MathStudy {
public static void main(String[] args) {
// TODO Auto-generated method stub
//求随机数
System.out.println(Math.random());
//5的2次方
System.out.println(Math.pow(5, 2));
//求绝对值
System.out.println(Math.abs(-1));
//求最大值(2个数)
System.out.println(Math.max(6, 3));
//求最小值
System.out.println(Math.min(6, 3));
//求2个数的乘积
System.out.println(Math.multiplyExact(12, 12));
//求相反数(1 的相反数是 -1)
System.out.println(Math.negateExact(-1));
//返回某一个数的四舍五入
System.out.println(Math.round(12.123));
}
}
