day08-static应用-Math-操作数学方法的工具类
This commit is contained in:
@@ -0,0 +1,25 @@
|
|||||||
|
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 Demo15 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//public static double abs(double a) :返回 double 值的绝对值。
|
||||||
|
System.out.println(Math.abs(-2));
|
||||||
|
System.out.println(Math.abs(-2.2));
|
||||||
|
//public static double ceil(double a) :返回大于等于参数的最小的整数。(向上取整)
|
||||||
|
System.out.println(Math.ceil(6.1));//7.0
|
||||||
|
System.out.println(Math.ceil(-3.6));//-3.0
|
||||||
|
//public static double floor(double a) :返回小于等于参数最大的整数。(向下取整)
|
||||||
|
System.out.println(Math.floor(4.9));//4.0;
|
||||||
|
System.out.println(Math.floor(-6.6));//-7.0
|
||||||
|
//public static long round(double a) :返回最接近参数的 long。(相当于四舍五入方法)
|
||||||
|
System.out.println(Math.round(3.4));//3
|
||||||
|
System.out.println(Math.round(4.6));//5
|
||||||
|
System.out.println(Math.round(-8.8));//
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user