--- id: java-operators-arithmetic title: "Java Operators Arithmetic" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["increment decrement", "자바 산술 연산자"] 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", "operators", "arithmetic", "increment"] raw_sources: ["https://www.w3schools.com/java/java_operators_arithmetic.asp"] applied_in: [] github_commit: "" --- # [[Java Operators Arithmetic]] ## 🎯 한 줄 통찰 (One-line insight) Dividing two `int` values ALWAYS truncates to an integer result (`10 / 3` gives `3`, not `3.33`) — getting a decimal result requires both operands to be `double`, making this a common source of silent precision loss for beginners. [S1] ## 🧠 핵심 개념 (Core concepts) - **Arithmetic operators** — `+`, `-`, `*`, `/`, `%` (modulus), `++` (increment), `--` (decrement). [S1] - **Integer division truncates** — `int / int` always yields an `int`, discarding any remainder. [S1] - **Double division preserves decimals** — `double / double` yields the actual fractional result. [S1] - **`++`/`--`** — increase/decrease a variable by exactly 1. [S1] - **Increment then decrement cancels out** — ending value equals the starting value. [S1] ## 🧩 추출된 패턴 (Extracted patterns) - **Integer division truncation is the classic footgun** — `10 / 3` silently gives `3` in Java (as in most statically-typed languages), unlike Python 3 where `/` always returns a float; this difference trips up developers moving between languages. [S1] - **Counter pattern via ++/--** — tracking a running count (e.g. people entering/leaving a room) is the canonical real-world use of increment/decrement. [S1] ## 📖 세부 내용 (Details) - All operators demoed: `int x = 10; int y = 3; println(x + y); println(x - y); println(x * y); println(x / y); println(x % y);`. [S1] - Integer vs. double division: `int a = 10; int b = 3; System.out.println(a / b); // 3 (truncated)` vs. `double c = 10.0d; double d = 3.0d; System.out.println(c / d); // 3.333...`. [S1] - Increment/decrement counter: `int peopleInRoom = 0; peopleInRoom++; peopleInRoom++; peopleInRoom--;`. [S1] ## ⚖️ 모순 및 업데이트 (Contradictions & updates) - **정수 나눗셈의 절삭 동작**: `int / int`는 항상 정수 결과를 반환하며 소수점 이하는 버려진다는 점이 명시적으로 경고됨 — Type Casting 챕터의 double 캐스팅 해법과 연결된다. [S1] ## 🛠️ 적용 사례 (Applied in summary) 현재 발견된 실제 적용 사례가 없습니다 — 사람 수 카운팅 같은 실전 예제에서 증감 연산자의 용도가 직접 등장한다. [S1] ## 💻 코드 패턴 (Code patterns) Integer division truncates, double division doesn't (Java): ```java int a = 10, b = 3; System.out.println(a / b); // 3 (truncated) double c = 10.0d, d = 3.0d; System.out.println(c / d); // 3.333... ``` ## ✅ 검증 상태 및 신뢰도 - **상태:** draft - **검증 단계:** conceptual - **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body) - **신뢰 점수:** 0.90 - **중복 검사 결과:** 신규 생성 (New discovery) ## 🔗 지식 그래프 (Knowledge Graph) - **상위/루트:** [[Java Tutorial]] - **관련 개념:** [[Java Operators]], [[Java Type Casting]], [[Java Numbers]] - **참조 맥락:** 정수 나눗셈 절삭 문제는 Type Casting 챕터의 double 캐스팅 해법과 직접 연결된다. ## 📚 출처 (Sources) - [S1] W3Schools — Java Arithmetic Operators — https://www.w3schools.com/java/java_operators_arithmetic.asp ## 📝 변경 이력 (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "Java Arithmetic Operators" page (Astra wiki-curation, P-Reinforce v3.1 format).