day08--static应用-Math-操作数学方法的工具类
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
package com.inmind.math04;
|
||||||
|
/*
|
||||||
|
Math工具类的使用
|
||||||
|
public static double abs(double a) :返回 double 值的绝对值。
|
||||||
|
public static double ceil(double a) :返回大于等于参数的最小的整数。
|
||||||
|
public static double floor(double a) :返回小于等于参数最大的整数。
|
||||||
|
public static long round(double a) :返回最接近参数的 long。(相当于四舍五入方法)
|
||||||
|
*/
|
||||||
|
public class MathDemo11 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
//获取绝对值
|
||||||
|
System.out.println(Math.abs(-100));//100
|
||||||
|
//向上取整
|
||||||
|
System.out.println(Math.ceil(-3.7));//-3.0
|
||||||
|
//向下取整
|
||||||
|
System.out.println(Math.floor(-3.4));//-4.0
|
||||||
|
//四舍五入
|
||||||
|
System.out.println(Math.round(4.4));//4
|
||||||
|
System.out.println(Math.round(4.5));//5
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user