--- id: java-math title: "Java Math" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["Math class", "์ž๋ฐ” ์ˆ˜ํ•™"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.9 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["java", "programming", "w3schools", "math"] raw_sources: ["https://www.w3schools.com/java/java_math.asp"] applied_in: [] github_commit: "" --- # [[Java Math]] ## ๐ŸŽฏ ํ•œ ์ค„ ํ†ต์ฐฐ (One-line insight) `Math.pow()` always returns a `double` even for whole-number results (`Math.pow(2,8)` gives `256.0`, not `256`), and `Math.random()` always returns a `double` in `[0.0, 1.0)`, requiring an explicit `(int)` cast plus scaling formula to get a bounded random integer. [S1] ## ๐Ÿง  ํ•ต์‹ฌ ๊ฐœ๋… (Core concepts) - **`Math.max(x,y)` / `Math.min(x,y)`** โ€” highest/lowest of two values. [S1] - **`Math.sqrt(x)`** โ€” square root. [S1] - **`Math.abs(x)`** โ€” absolute value. [S1] - **`Math.pow(x,y)`** โ€” x raised to power y; ALWAYS returns double. [S1] - **Rounding methods** โ€” `Math.round(x)` (nearest integer), `Math.ceil(x)` (round up), `Math.floor(x)` (round down). [S1] - **`Math.random()`** โ€” random double in `[0.0, 1.0)`. [S1] - **Bounded random integer formula** โ€” `(int)(Math.random() * 101)` for 0-100. [S1] ## ๐Ÿงฉ ์ถ”์ถœ๋œ ํŒจํ„ด (Extracted patterns) - **pow() always returns double** โ€” even `Math.pow(2, 8)` (a clean integer result) comes back as `256.0`, not `256` โ€” a type consistency rule worth remembering when assigning the result to a variable. [S1] - **random-int-in-range formula** โ€” `(int)(Math.random() * (max+1))` scales the `[0,1)` double up to the desired range and truncates via cast โ€” the standard idiom for bounded random integers. [S1] ## ๐Ÿ“– ์„ธ๋ถ€ ๋‚ด์šฉ (Details) - Max/min: `Math.max(5, 10); Math.min(5, 10);`. [S1] - Square root/absolute: `Math.sqrt(64); Math.abs(-4.7);`. [S1] - Power (always double): `Math.pow(2, 8); // 256.0`. [S1] - Rounding: `Math.round(4.6); // 5`, `Math.ceil(4.1); // 5.0`, `Math.floor(4.9); // 4.0`. [S1] - Bounded random int: `int randomNum = (int)(Math.random() * 101); // 0 to 100`. [S1] ## โš–๏ธ ๋ชจ์ˆœ ๋ฐ ์—…๋ฐ์ดํŠธ (Contradictions & updates) - **pow()์˜ ๋ฐ˜ํ™˜ ํƒ€์ž…**: ๊ฒฐ๊ณผ๊ฐ€ ์ •์ˆ˜์—ฌ๋„ ํ•ญ์ƒ double์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค๋Š” ์ ์ด ์†Œ์Šค์—์„œ ๋ช…์‹œ์ ์œผ๋กœ ๊ฐ•์กฐ๋จ. [S1] ## ๐Ÿ› ๏ธ ์ ์šฉ ์‚ฌ๋ก€ (Applied in summary) ํ˜„์žฌ ๋ฐœ๊ฒฌ๋œ ์‹ค์ œ ์ ์šฉ ์‚ฌ๋ก€๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค โ€” 0~100 ์‚ฌ์ด ๋‚œ์ˆ˜ ์ƒ์„ฑ ๊ณต์‹์€ ๊ฒŒ์ž„/์‹œ๋ฎฌ๋ ˆ์ด์…˜์—์„œ ํ‘œ์ค€์ ์œผ๋กœ ์“ฐ์ธ๋‹ค. [S1] ## ๐Ÿ’ป ์ฝ”๋“œ ํŒจํ„ด (Code patterns) Bounded random integer via cast (Java): ```java int randomNum = (int)(Math.random() * 101); // 0 to 100 ``` ## โœ… ๊ฒ€์ฆ ์ƒํƒœ ๋ฐ ์‹ ๋ขฐ๋„ - **์ƒํƒœ:** draft - **๊ฒ€์ฆ ๋‹จ๊ณ„:** conceptual - **์ถœ์ฒ˜ ์‹ ๋ขฐ๋„:** B (W3Schools โ€” widely used educational reference, not a primary standards body) - **์‹ ๋ขฐ ์ ์ˆ˜:** 0.90 - **์ค‘๋ณต ๊ฒ€์‚ฌ ๊ฒฐ๊ณผ:** ์‹ ๊ทœ ์ƒ์„ฑ (New discovery) ## ๐Ÿ”— ์ง€์‹ ๊ทธ๋ž˜ํ”„ (Knowledge Graph) - **์ƒ์œ„/๋ฃจํŠธ:** [[Java Tutorial]] - **๊ด€๋ จ ๊ฐœ๋…:** [[Java Numbers]], [[Java Type Casting]], [[Python Math]] - **์ฐธ์กฐ ๋งฅ๋ฝ:** ์ˆ˜ํ•™ ๊ณ„์‚ฐ์˜ ๊ธฐ๋ณธ ๋„๊ตฌ โ€” pow()์˜ double ๋ฐ˜ํ™˜, random() ๋ฒ”์œ„ ์ง€์ • ๊ณต์‹์ด ํ•ต์‹ฌ. ## ๐Ÿ“š ์ถœ์ฒ˜ (Sources) - [S1] W3Schools โ€” Java Math โ€” https://www.w3schools.com/java/java_math.asp ## ๐Ÿ“ ๋ณ€๊ฒฝ ์ด๋ ฅ (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "Java Math" page (Astra wiki-curation, P-Reinforce v3.1 format).