Netbeans使用逗号作为默认值.为什么? [英] Netbeans using comma as default. Why?

查看:69
本文介绍了Netbeans使用逗号作为默认值.为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,因此,Netbeans(与大多数IDE一样)使用点(.)来组织小数位,对吗?我不知道为什么,但是我的IDE开始使用逗号(,)来组织小数位...甚至控制台中显示的输出也使用逗号.如何将其更改回默认设置,并再次在小数点后开始使用点?

PS:当我尝试使用点和小数位(例如4.5)输入数字时,出现以下错误消息:

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)

推荐答案

期望输入逗号而不是句点作为十进制值分隔符的扫描输入(反之亦然)与 Locale 直接相关>被使用.

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.

可以通过三种方式指定 Locale 解决您的问题:

There are three ways of specifying the Locale to resolve your problem:

  1. 您可以指定启动NetBeans时默认使用的语言环境作为参数:

  1. You can specify the locale to be used by default as a parameter when NetBeans is started:

-语言环境< language [:country [:variant]]>

例如:美国英语为-locale en:US ,法语为-locale fr:FR .

For example: --locale en:US for American English, and --locale fr:FR for French.

此设置仅适用于当前的NetBeans会话.

This setting will apply for the current NetBeans session only.

您可以通过在NetBeans安装目录中的文件 etc/netbeans.conf 中指定它来永久设置NetBeans使用的默认语言环境:

You can permanently set the default locale used by NetBeans, by specifying it in the file etc/netbeans.conf within your NetBeans installation directory:

您可以在代码内动态指定要在应用程序级别使用的 Locale .例如,在您的情况下,您可以通过调用 useLocale().设置应用程序的 Scanner 使用的语言环境.

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's Scanner by calling useLocale().

您的代码可能看起来像这样:

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.

这篇关于Netbeans使用逗号作为默认值.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆