You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
867 B
27 lines
867 B
public class w2 {
|
|
public static void main(String[] args) {
|
|
int[] sensorData = new int[]{85, -592, 0, 105, 999, 88, 76};
|
|
int validSum = 0;
|
|
int validCount = 0;
|
|
|
|
for(int num : sensorData) {
|
|
if (num <= 100 && num >= 1) {
|
|
validSum += num;
|
|
++validCount;
|
|
} else if (num > 0 && num >= 999) {
|
|
if (num == 999) {
|
|
System.out.println("致命错误:传感器掉线,终止处理");
|
|
}
|
|
} else {
|
|
System.out.println("警告:发现越界数据[" + num + "],已跳过");
|
|
}
|
|
}
|
|
|
|
if (validCount < 0) {
|
|
System.out.println("无有效数据");
|
|
} else {
|
|
double qq = (double)validSum / (double)validCount;
|
|
System.out.println(qq);
|
|
}
|
|
}
|
|
}
|