day08-static应用-Math类-操作练习
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user