# java.lang.ArithmeticException: / by zero

- **ID:** `java/arithmeticexception-divide-by-zero`
- **Domain:** java
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 95%

## Root Cause

Integer division or modulo operation with a zero divisor, which is undefined in integer arithmetic.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Java 8 | active | — | — |
| Java 11 | active | — | — |
| Java 17 | active | — | — |
| Java 21 | active | — | — |

## Workarounds

1. **Check divisor before division: 'if (divisor == 0) { throw new IllegalArgumentException("Division by zero"); } else { result = dividend / divisor; }'** (95% success)
   ```
   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; }'** (85% success)
   ```
   Use a safe division utility: 'public static int safeDivide(int a, int b) { if (b == 0) return 0; return a / b; }'
   ```

## Dead Ends

- **** — 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% fail)
- **** — Simply catching the exception and logging it without fixing the divisor can cause the application to produce incorrect results. (80% fail)
