day08--Math工具类

This commit is contained in:
2026-01-05 10:52:53 +08:00
parent fd93b6bb4c
commit 19be654735

View File

@@ -13,4 +13,21 @@ public static double floor(double a) :返回小于等于参数最大的整数
public static long round(double a) :返回最接近参数的 long。(相当于四舍五入方法) public static long round(double a) :返回最接近参数的 long。(相当于四舍五入方法)
*/ */
public class Demo15 { public class Demo15 {
public static void main(String[] args) {
//取值范围: -10.8 ~5.9
double start = -10.8;
double end = 5.9;
//定义计数的变量
int count = 0;
for (double i = Math.ceil(start); i < end; i++) {
//判断条件:绝对值>6||<2.1
if (Math.abs(i) > 6 || Math.abs(i) < 2.1) {
System.out.println(i);
count++;
}
}
System.out.println("满足条件的个数:"+count);
}
} }