Issue
Hello guys and girls, So, Netbeans (like most IDE's) use dots (.) to organize decimal places, right? I dont know why but my IDE began to use comma (,) to organize decimal places... even the outputs showed in the console are using commas. How can i change it back to default settings and start using dot in decimal places again?
PS: When i try to enter a number using dot and the decimal places (4.5, for example) i get this error message:
Exception in thread "main" java.util.InputMismatchException
at java.base/java.util.Scanner.throwFor(Scanner.java:939)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextDouble(Scanner.java:2564)
at EstruturasDeControle.If.main(If.java:16)
Command execution failed.
org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1)
at org.apache.commons.exec.DefaultExecutor.executeInternal(DefaultExecutor.java:404)
at org.apache.commons.exec.DefaultExecutor.execute(DefaultExecutor.java:166)
at org.codehaus.mojo.exec.ExecMojo.executeCommandLine(ExecMojo.java:764)
at org.codehaus.mojo.exec.ExecMojo.executeCommandLine(ExecMojo.java:711)
at org.codehaus.mojo.exec.ExecMojo.execute(ExecMojo.java:289)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Solution
Scanning input which expects a comma rather than a period as the separator for decimal values (or vice versa) is directly related to the Locale
being used.
There are three ways of specifying the Locale
to resolve your problem:
You can specify the locale to be used by default as a parameter when NetBeans is started:
--locale <language[:country[:variant]]>
For example:
--locale en:US
for American English, and--locale fr:FR
for French.This setting will apply for the current NetBeans session only.
You can permanently set the default locale used by NetBeans, by specifying it in the file etc/netbeans.conf within your NetBeans installation directory:
- Open that file in any text editor.
- Locate the line containing the text netbeans_default_options
- Add the values to specify the language and country of the locale. for example, to set the locale to US English:
-J-Duser.language=en -J-Duser.country=US
- See the article Change UI language to English on Netbeans IDE for more details.
You can dynamically specify the
Locale
to be used at the application level within the code. For example, in your case you could set the locale used by your application'sScanner
by callinguseLocale()
.
Your code code might look like this:
Scanner scanner = new Scanner(System.in);
scanner.useLocale(Locale.US); // US locale, so period is expected for numeric input.
...
scanner.useLocale(Locale.FR); // France locale, so comma is expected for numeric input.
All three approaches can resolve your problem, and you can use any or all of them. Your specific needs determine the one(s) to be used.
Answered By - skomisa
Answer Checked By - David Goodson (JavaFixing Volunteer)