Mate算术运算类
public class Math算术运算类 {
/**
* public final class Math extends Object
* 可以看出,Math 类是一个最终类,也就是说,它不能被继承,更不能被重写。
* Math 类中的方法全部为静态方法,直接使用就行。
*/
public static void main(String[] args) {
// 绝对值
System.out.println("-1的绝对值:Math.abs(-1) = " + Math.abs(-1));
// 比这个数大的最小整数
System.out.println("比9.01大的最小整数:Math.ceil(9.01) = " + Math.ceil(9.01));
// 比这个数小的最大整数
System.out.println("比9.99小的最大的整数:Math.floor(9.99) = " + Math.floor(9.99));
// 取较大者
System.out.println("取两者的较大者:Math.max(101, 276.0001) = " + Math.max(101, 276.0001));
// 随机数,区间为[0.0, 1.0)
System.out.println("取[0.0, 1.0) 之间的随机数:Math.random() = " + Math.random());
// 四舍五入
System.out.println("取 9.49 的四舍五入值:Math.round(9.49) = " + Math.round(9.49));
// 返回正确传入的 double 值的正平方根
System.out.println("取 255 的正平方根:Math.sqrt(225) = " + Math.sqrt(225));
}
}
运行截图
![Math算术运算类.jpg Math算术运算类.jpg]()