# java.util.InputMismatchException

- **ID:** `java/inputmismatchexception`
- **Domain:** java
- **Category:** type_error
- **Verification:** ai_generated
- **Fix Rate:** 88%

## Root Cause

The input token does not match the expected type when using a Scanner, often due to incorrect locale or unexpected data format.

## Version Compatibility

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

## Workarounds

1. **Use hasNextInt() before nextInt(): 'if (scanner.hasNextInt()) { int value = scanner.nextInt(); } else { scanner.next(); /* consume invalid token */ }'** (90% success)
   ```
   Use hasNextInt() before nextInt(): 'if (scanner.hasNextInt()) { int value = scanner.nextInt(); } else { scanner.next(); /* consume invalid token */ }'
   ```
2. **Set the locale to match the input format: 'scanner.useLocale(Locale.US);' for decimal numbers with dot separator.** (85% success)
   ```
   Set the locale to match the input format: 'scanner.useLocale(Locale.US);' for decimal numbers with dot separator.
   ```

## Dead Ends

- **** — Setting the locale to US (Locale.US) may not fix the issue if the input contains non-numeric characters. (60% fail)
- **** — Using next() instead of nextInt() and then manually parsing can still throw NumberFormatException if the string is malformed. (70% fail)
