From 1c26ce71db061f2ccb58190197f1a2bddf224636 Mon Sep 17 00:00:00 2001 From: zhouzihao Date: Thu, 19 Mar 2026 14:41:48 +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=E5=91=A8=E6=A2=93=E6=B5=A9202506050319'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- W2周梓浩202506050319/DataCleaner.java | 34 ++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 W2周梓浩202506050319/DataCleaner.java diff --git a/W2周梓浩202506050319/DataCleaner.java b/W2周梓浩202506050319/DataCleaner.java new file mode 100644 index 0000000..31a708d --- /dev/null +++ b/W2周梓浩202506050319/DataCleaner.java @@ -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=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("无有效数据"); + } + } +}