【问题标题】:Remove question mark from Command Prompt [Java]从命令提示符中删除问号 [Java]
【发布时间】:2015-04-08 02:34:38
【问题描述】:

您好,我正在尝试对纬度数进行子串化 北纬 43° 41'

 lat1 = latitude[curIndex1].substring(0, (latitude[curIndex1].indexOf("°")));


        System.out.println(lat1);
        lat1Converted = Double.parseDouble(lat1);

我在 netbeans 中运行程序,当我打印 lat1 时,它显示 43

但是,当我进入命令提示符时,我收到一个错误,因为它认为 43 之后有一个问号。

当它打印出 lat 1 时,它显示的是 43?

因此,我无法将其转换为双精度,然后无法使用它来查找两个地方之间的距离,因此它崩溃了。

我不知道为什么会这样。

【问题讨论】:

  • 控制台无法用当前字体渲染度数字符
  • 是的@MadProgrammer 是正确的。您可以将 Netbeans 中使用的字体添加到您的系统中吗?
  • 它使用的是 Lucida Console 14,这是命令提示符使用正确的字体吗?

标签: java arrays substring latitude-longitude


【解决方案1】:

不要依赖学位:

Pattern p = Pattern.compile("-?\\d+"); // extracts numbers
Matcher m = p.matcher(latitude);
int degrees = m.find() ? Integer.parseInt(m.group()) : 0;
int minutes = m.find() ? Integer.parseInt(m.group()) : 0;
int seconds = m.find() ? Integer.parseInt(m.group()) : 0;

【讨论】:

    猜你喜欢
    • 2011-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-25
    • 1970-01-01
    相关资源
    最近更新 更多