From 6420f81c0a68c6fc4b533fbaf38da5d0c5c3a080 Mon Sep 17 00:00:00 2001 From: YuWeixia Date: Sun, 15 Mar 2026 21:47:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20'w2'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- w2/DataCleaner.class | Bin 0 -> 1349 bytes w2/DataCleaner.java | 64 +++++++++++++++++++++---------------------- 2 files changed, 32 insertions(+), 32 deletions(-) create mode 100644 w2/DataCleaner.class diff --git a/w2/DataCleaner.class b/w2/DataCleaner.class new file mode 100644 index 0000000000000000000000000000000000000000..6e347c1b4eec4f14b01671f8ca4d9015680400da GIT binary patch literal 1349 zcmaJ>-)~b@9RHl%+n%l~>)qxZY;-tv=n8HX(IJ%W!4h;yp(LHt1`<8%Zs5}P-lq4C zxcEZiVi^H+35!A$Ct1V?CkTW=sqpUK!ENgkuSSjdy)DL)HQtBw<9k2f@ArH@=leas z{#|+iU>y7XXoJKd2jGF1K{+W-iAYu$$0LcElUmwl@b1?Q-JW2OhQrhC@S&ZF^we;|D`CRq>nabK#XLX_a#bC7RKuj4shCLLNpIffb9j!rW8ljd9@tsT_e=t|QeMqT;H z^tNf*mR%6}Lz;cUoV9{pjQBB%2*+zK*If)l|5bu+oH8?7q#O*=$m`HLA7U4B^_^ z_s-H;sxs&ErRs$nwL534%jX(5G{~sbob{Wv^;@-vMIYW|2sPiJbMKb(P0=}Bess4) z0T@GI(x8isWrbyF7ROr*+c${RiaWE-sr;ky1&J+q*|jHk2d 100) { - System.out.println("警告:发现越界数据 " + value + ",已跳过"); - continue; - } - - // 有效数据(1到100之间) - validSum += value; - validCount++; - } - - // 输出结果 - if (validCount > 0) { - double average = (double) validSum / validCount; - System.out.println("有效数据平均值为:" + average); - } else { - System.out.println("无有效数据"); - } - } +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 value : sensorData) { + if (value == 999) { + System.out.println("致命错误:传感器掉线,终止处理"); + break; + } + + if (value <= 0 || value > 100) { + System.out.println("警告:发现越界数据 " + value + ",已跳过"); + continue; + } + + // 有效数据(1到100之间) + validSum += value; + validCount++; + } + + // 输出结果 + if (validCount > 0) { + double average = (double) validSum / validCount; + System.out.println("有效数据平均值为:" + average); + } else { + System.out.println("无有效数据"); + } + } } \ No newline at end of file