day08-static应用-Math类-操作练习

This commit is contained in:
2026-05-20 10:01:14 +08:00
parent e388c1b3be
commit a65790adce

View File

@@ -1,4 +1,4 @@
package com.inmind.arrays03;
package com.inmind.math04;
/*
计算在 -10.8 到5.9 之间绝对值大于6 或者小于2.1 的整数有多少个?
分析:
@@ -7,4 +7,19 @@ package com.inmind.arrays03;
定义一个变量来计数
*/
public class Test16 {
public static void main(String[] args) {
double start = -10.8;
double end = 5.9;
int count = 0;
for (double i = Math.ceil(start); i < end ; i++) {
System.out.print(i+" ");
//条件>6||<2.1
if (Math.abs(i) > 6 || Math.abs(i) < 2.1) {
count++;
}
}
System.out.println();
System.out.println(count);
}
}