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.
28 lines
984 B
28 lines
984 B
public class DataCleaner {
|
|
public static void main(String[] args) {
|
|
int[] sensorData = {85, -5, 92, 0, 105, 999, 88, 76};
|
|
|
|
int validSum = 0; // 有效数据总和
|
|
int validCount = 0; // 有效数据个数
|
|
for (int i = 0; i < sensorData.length; i++) {
|
|
int CurrentData = sensorData[i];
|
|
if (CurrentData == 999 ) {
|
|
System.out.println("致命错误:传感器掉线,终止处理");
|
|
break;
|
|
}
|
|
if (CurrentData >= 1 && CurrentData <= 100) {
|
|
validSum += CurrentData;
|
|
validCount++;
|
|
} else {
|
|
System.out.println("警告:发现越界数据 "+CurrentData+",已跳过");
|
|
continue;
|
|
}
|
|
}
|
|
if (validSum > 0) {
|
|
double averagevalidSum = (double) validSum / validCount;
|
|
System.out.println(averagevalidSum);
|
|
} else {
|
|
System.out.println("无有效数据");
|
|
}
|
|
}
|
|
}
|