java.util.InputMismatchException (Scanner)
Scanner.nextInt()/nextDouble() read a token that isn’t that type.
Seen on:
Java
Meaning
Typing text where a number is expected, locale decimal separators (3,5 vs 3.5) or leftover newline handling cause it.
Common causes
- Non-numeric input
- Locale using comma decimals
- Mixing nextInt() and nextLine()
⚡ Quick fix
- Check hasNextInt() before nextInt()
- Set scanner.useLocale(Locale.US)
- Read lines and parse with validation
Detailed fix by platform
Java
while (!sc.hasNextInt()) { sc.next(); System.out.print("Enter a number: "); }
How to diagnose
- Input — What token was read?
- Locale — Decimal separator?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026