Question: Why does my code crash when nextDouble
picks up a decimal with a dot .
?
Answer: Your Scanner
's locale is French, which uses ,
for decimals. Tell Scanner
to use an English locale.
import java.util.Locale; Scanner scan = new Scanner(System.in).useLocale(Locale.ENGLISH);
As you autocompleteLocale
, make sure it gets imported (see line 1).