3 changed files with 27 additions and 0 deletions
|
After Width: | Height: | Size: 606 KiB |
Binary file not shown.
@ -0,0 +1,27 @@ |
|||
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 num : sensorData){ |
|||
if (num==999){ |
|||
System.out.println("致命错误:传感器掉线,终止处理"); |
|||
break; |
|||
} |
|||
if (num<1 || num>100) { |
|||
System.out.println("警告,发现越界数据,["+num+"],已跳过。"); |
|||
continue; |
|||
} |
|||
validSum+=num; |
|||
validCount++; |
|||
} |
|||
if(validCount>0){ |
|||
double average = (double)validSum/validCount; |
|||
System.out.println("有效数据的平均值:"+average); |
|||
}else{ |
|||
System.out.println("无有效数据"); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue