有谁知道为什么数字0.001到0.009被呈现给一个尾随0的字符串,但其他数字没有.例如,数字0.01到0.09没有.
System.out.println(Locale.getDefault());
for (int i = 0; i <= 20; i++)
System.out.println(i / 1e3);
Run Code Online (Sandbox Code Playgroud)
版画
en_GB
0.0
0.0010
0.0020
0.0030
0.0040
0.0050
0.0060
0.0070
0.0080
0.0090
0.01
0.011
0.012
0.013
0.014
0.015
0.016
0.017
0.018
0.019
0.02
Run Code Online (Sandbox Code Playgroud)
编辑DecimalFormat的代码似乎不依赖于语言环境.如果我跑
for (Locale l : Locale.getAvailableLocales()) {
Locale.setDefault(l);
System.out.println(l + " " + 1 / 1e3);
}
Run Code Online (Sandbox Code Playgroud)
在Ubuntu 11.04上的Java 6更新26上,我得到了
ja_JP 0.0010
es_PE 0.0010
en 0.0010
... many locales with the same result ...
sv_SE 0.0010
da_DK 0.0010
es_HN 0.0010
Run Code Online (Sandbox Code Playgroud)
在我得到的同一系统上的Java 7上
ms_MY …Run Code Online (Sandbox Code Playgroud) 为什么评论显着加快?弹出,比较和长度检查不应该是O(1)吗?这会显着影响速度吗?
#! /usr/bin/python
import math
pmarbs = []
pows = 49
pmarbs.append("W")
inc = 1
for i in range(pows):
count = 0
j = 0
ran = int(pow(2, i))
marker = len(pmarbs) - inc
while (j < ran):
#potential marble choice
pot = pmarbs[marker - j]
pot1 = pot + "W"
pot2 = pot + "B"
if (pot2.count('W') < pot2.count('B')) and (len(pot2) > (i+1)):
count += 1
else:
pmarbs.append(pot2)
pmarbs.append(pot1)
# if(len(pmarbs[0]) < i):
# pmarbs.pop(0)
# marker -= 1 …Run Code Online (Sandbox Code Playgroud) 我有一个普通的java问题,我正在寻找答案.假设我有一个属性高度的对象,我有一个使用高度进行计算的方法.将属性高度传递给方法是否更好,或者传递完整对象并使用getter来检索高度值是否更好.我希望这是有道理的.
例如
public getHeightInMeters(Object object) {
return object.getHeight()*x;
}
Run Code Online (Sandbox Code Playgroud)
是相同,更糟,更好?
public getHeightInMeters(Height height) {
return height*x;
}
Run Code Online (Sandbox Code Playgroud) 是否可以在命令行中运行java类来在正在运行的swing中运行某个类或函数?
比如,什么时候java Test asd将setText运行一个Jlabel到asd
我将一些计算例程从.Net移植到Java但是在Date类中似乎存在一些精度问题.也许我已经盯着自己,但我无法弄清楚为什么结果会有所不同.
我应该如何处理日期以获得跨平台的相同数字(毫秒)?
.净
[Test] public void foo() {
DateTime dt1 = new DateTime(2011, 2, 26, 19, 25, 24);
DateTime dt2 = new DateTime(2011, 2, 28, 18, 40, 25);
double millis = (dt2 - dt1).TotalMilliseconds;
Assert.AreEqual(170101000, millis);
}
Run Code Online (Sandbox Code Playgroud)
Java的
@Test public void foo() throws Exception {
Date d1 = createDate(2011, 2, 26, 19, 25, 24);
Date d2 = createDate(2011, 2, 28, 18, 40, 25);
long millis = d2.getTime() - d1.getTime();
Assert.assertEquals(166501000, millis, 0.01);
}
private static Date createDate(int year, int month, …Run Code Online (Sandbox Code Playgroud) 我有一个静态参考变量
static IMail mailer = null;
Run Code Online (Sandbox Code Playgroud)
在类SearchManager的构造函数中为其分配值的对象
public SearchManager(ILog logger, String basePath, String indexPath, String nwId, IMail mailer) {
this.logger = logger;
this.basePath = basePath;
this.indexPath = indexPath;
this.nwId = nwId;
this.mailer = mailer;
}
Run Code Online (Sandbox Code Playgroud)
我在代码中使用了邮件程序。此类的构造函数可能被多次调用。因此,我有一个查询,该静态引用变量在每次调用构造函数时将如何表现。是只接受我第一次调用构造函数时传递的值,还是每次调用构造函数时都取不同的值?