Scanner double value – InputMismatchException

You should precise a Locale for your Scanner.

Scanner scanner = new Scanner(System.in).useLocale(Locale.US);

From the doc :

An instance of this class is capable of scanning numbers in the
standard formats as well as in the formats of the scanner’s locale. A
scanner’s initial locale is the value returned by the
Locale.getDefault() method; it may be changed via the
useLocale(java.util.Locale) method

The localized formats are defined in terms of the following
parameters, which for a particular locale are taken from that locale’s
DecimalFormat object, df, and its and DecimalFormatSymbols object,
dfs.

So your default locale use certainly a DecimalFormat that expect a comma as a decimal delimiter instead of a dot.

Leave a Comment