1 changed files with 34 additions and 0 deletions
@ -0,0 +1,34 @@ |
|||
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++) { |
|||
if (sensorData[i]==999) { |
|||
System.out.println("致命错误:传感器掉线,终止处理"); |
|||
break; |
|||
} |
|||
if (sensorData[i]>=1&&sensorData[i]<=100) { |
|||
validSum+=sensorData[i]; |
|||
validCount++; |
|||
} |
|||
else { |
|||
System.out.println("警告:发现越界数据"+sensorData[i]+",已跳过"); |
|||
continue; |
|||
} |
|||
|
|||
|
|||
} |
|||
|
|||
if (validCount>0){ |
|||
double pjs=(double) validSum/validCount; |
|||
System.out.println(pjs); |
|||
} |
|||
else { |
|||
System.out.println("无有效数据"); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue