day08-static应用-Math类-操作数学方法的工具类

This commit is contained in:
2026-01-22 11:15:18 +08:00
parent 4261fd9fd6
commit b8aff9d0c6
2 changed files with 36 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
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));//2
System.out.println(Math.abs(-2.2));//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));//-9
}
}

View File

@@ -0,0 +1,10 @@
package com.inmind.math04;
/*
计算在 -10.8 到5.9 之间绝对值大于6 或者小于2.1 的整数有多少个?
分析:
取值范围: -10.8 ~5.9
条件>6||<2.1
定义一个变量来计数
*/
public class Test16 {
}