安全漏洞,我昨天采访了这问题就出来了:凡在这双重比较
public class Main {
public static void main(String[] args) {
// Code fragment must prints true if the double variables x and y are both
// strictly between 0 and 1 and false otherwise.
// Assuming args will be always correct (double) input,
// Where's the safety bug?
double x,y;
x = Double.parseDouble(args[0]);
y = Double.parseDouble(args[1]);
System.out.println((0 < x && x < 1) && (0 < y && y < 1)? true : false);
}
}
我写的有没有任何地方的错误,我的意思是,代码工作。回到家中,尝试过,确实很有效。但是,尽管我确实得到了这份工作,但这个问题是我唯一的错误,而且我无法摆脱我的头脑(这简直就是公平直截了当)。我相信我甚至不明白什么是安全错误,那么我的问题是:
什么是安全错误,这个代码的确有一个?
UPDATE:
响应后我把一些相关的资源:
Eric Lippert的Why does JScript have rounding errors?
既然你找到了工作,为什么你不能问问你的面试官? –
问题的一部分是这个问题的含糊性。我们在谈论什么样的安全?线程安全?类型安全?安全? – Jeremy
@MattBall没有说。其他候选人在下午被问到。 –