From c02d15d2247f19126b4249f9265e3ac681cefd77 Mon Sep 17 00:00:00 2001 From: Bilei <3354484301@qq.com> Date: Thu, 12 Mar 2026 11:56:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BC=82=E5=B8=B8=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- w2/DataCleaner.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/w2/DataCleaner.java b/w2/DataCleaner.java index 9171b53..53213f7 100644 --- a/w2/DataCleaner.java +++ b/w2/DataCleaner.java @@ -1,30 +1,22 @@ 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; // 有效数据个数 - + int validSum = 0; + int validCount = 0; for (int num : sensorData) { - // 规则3:致命错误,遇到999终止流程 if (num == 999) { System.out.println("致命错误:传感器掉线,终止处理"); break; } - - // 规则2:无效数据,跳过当前循环 if (num <= 0 || (num > 100 && num != 999)) { System.out.println("警告:发现越界数据[" + num + "],已跳过"); continue; } - - // 规则1:正常范围,计入有效数据 if (num >= 1 && num <= 100) { validSum += num; validCount++; } } - - // 规则4:最终输出 if (validCount > 0) { double average = (double) validSum / validCount; System.out.println("有效数据平均值:" + average);