--- id: java-arrays-real-life title: "Java Arrays Real Life" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["자바 배열 실전 예제"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.87 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["java", "programming", "w3schools", "arrays", "examples"] raw_sources: ["https://www.w3schools.com/java/java_arrays_reallife.asp"] applied_in: [] github_commit: "" --- # [[Java Arrays Real Life]] ## 🎯 한 줄 통찰 (One-line insight) The min/max-tracking pattern initializes BOTH tracker variables to `numbers[0]` (not 0 or some sentinel), which is the safe idiom for arrays containing negative numbers — seeding with 0 would silently break the min-tracking logic if all elements were negative. [S1] ## 🧠 핵심 개념 (Core concepts) - **Average calculation** — sum via for-each, then divide by `.length`. [S1] - **Lowest-value tracker** — initialize a tracker to the first element, then compare/update while iterating. [S1] - **Break/continue array filtering** — skip negatives, stop at zero (reusing the break/continue chapter's pattern). [S1] - **Max+min simultaneous tracking** — two trackers both initialized to `numbers[0]`, updated independently in one loop pass. [S1] - **Indexed labeling** — seat number + occupant, requiring the regular for loop. [S1] ## 📖 세부 내용 (Details) - Average: `int ages[] = {20, 22, 18, 35, 48, 26, 87, 70}; float avg, sum = 0; int length = ages.length; for (int age : ages) { sum += age; } avg = sum / length;`. [S1] - Lowest value: `int lowestAge = ages[0]; for (int age : ages) { if (lowestAge > age) { lowestAge = age; } }`. [S1] - Skip negative/stop at zero: `int[] numbers = {3, -1, 7, 0, 9}; for (int n : numbers) { if (n < 0) { continue; } if (n == 0) { break; } System.out.println(n); }`. [S1] - Max and min together: `int[] numbers = {45, 12, 98, 33, 27}; int max = numbers[0]; int min = numbers[0]; for (int n : numbers) { if (n > max) { max = n; } if (n < min) { min = n; } }`. [S1] ## ⚖️ 모순 및 업데이트 (Contradictions & updates) 소스에서 모순되는 정보는 발견되지 않음. ## 🛠️ 적용 사례 (Applied in summary) 현재 발견된 실제 적용 사례가 없습니다 — 평균/최댓값/최솟값 계산은 배열 처리의 가장 흔한 실전 응용이다. [S1] ## 💻 코드 패턴 (Code patterns) Simultaneous max/min tracking seeded from first element (Java): ```java int[] numbers = {45, 12, 98, 33, 27}; int max = numbers[0]; int min = numbers[0]; for (int n : numbers) { if (n > max) { max = n; } if (n < min) { min = n; } } System.out.println("Max: " + max); System.out.println("Min: " + min); ``` ## ✅ 검증 상태 및 신뢰도 - **상태:** draft - **검증 단계:** conceptual - **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body) - **신뢰 점수:** 0.87 - **중복 검사 결과:** 신규 생성 (New discovery) ## 🔗 지식 그래프 (Knowledge Graph) - **상위/루트:** [[Java Tutorial]] - **관련 개념:** [[Java Arrays Loop]], [[Java Break Continue]], [[Java Arrays Multi]] - **참조 맥락:** 배열 순회의 실전 응용(평균/최대/최소) — 다차원 배열로 확장. ## 📚 출처 (Sources) - [S1] W3Schools — Java Arrays - Real-Life Examples — https://www.w3schools.com/java/java_arrays_reallife.asp ## 📝 변경 이력 (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "Java Arrays - Real-Life Examples" page (Astra wiki-curation, P-Reinforce v3.1 format).