day08-Math练习

This commit is contained in:
2026-07-25 10:16:05 +08:00
parent c42c542812
commit e05426d3a5
+24
View File
@@ -0,0 +1,24 @@
package com.inmind.math04;
/*
计算在 -10.8 到5.9 之间,绝对值大于6 或者小于2.1 的整数有多少个?
分析:
取值范围: -10.8 ~5.9
条件>6||<2.1
定义一个变量来计数
*/
public class Test16 {
public static void main(String[] args) {
int count = 0;//定义变量来计数
double start = -10.8;
double end = 5.9;
//取值范围: -10.8 ~5.9
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);
}
}