# java.lang.ArithmeticException: 除以零

- **ID:** `java/arithmeticexception-divide-by-zero`
- **领域:** java
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

整数除法或取模运算的除数为零，这在整数算术中未定义。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Java 8 | active | — | — |
| Java 11 | active | — | — |
| Java 17 | active | — | — |
| Java 21 | active | — | — |

## 解决方案

1. ```
   Check divisor before division: 'if (divisor == 0) { throw new IllegalArgumentException("Division by zero"); } else { result = dividend / divisor; }'
   ```
2. ```
   Use a safe division utility: 'public static int safeDivide(int a, int b) { if (b == 0) return 0; return a / b; }'
   ```

## 无效尝试

- **** — Using floating-point division (e.g., double) instead of integer division avoids the exception but may produce Infinity or NaN, which can propagate silently. (75% 失败率)
- **** — Simply catching the exception and logging it without fixing the divisor can cause the application to produce incorrect results. (80% 失败率)
