我正在尝试计算一些双形式数字的 log 2 基数,但似乎图书馆没有为此提供标准方法。
我尝试了这段代码,但发生了错误。
double entropy=0;
for(int i=0; i<26;i++){
entropy+=-possibilityCounter[i]*log2(possibilityCounter[i]);
}
Run Code Online (Sandbox Code Playgroud)
注意:可能计数器表充满了双变量,例如 0.00133536
有什么建议吗?
我给出了一个 LocalDate 值,然后我想给出另一个值,但我想确保新的值与之前的值不同。我写了一些代码,但似乎不起作用。
Flight flight = new Flight();
System.out.println("Give the day of the departure.");
LocalDate day = LocalDate.of(2019, Month.MAY, scanner.nextInt());
flight.setDateOfDeparture(day);
boolean theDay = true; //Flag (reversed way in order to achieve the TRUE logic value).
for (Flight flight1 : flightList) {
if (flight1.getDateOfDeparture() == (flight.getDateOfDeparture())) {
theDay = false;
}
}
if (theDay) {
// Some logic...
}
Run Code Online (Sandbox Code Playgroud)
我也尝试了关键字 equals 。但 for 循环再次忽略比较。
for (Flight flight1 : flightList) {
if (flight1.getDateOfDeparture().equals(flight.getDateOfDeparture())) {
theDay = false;
}
}
Run Code Online (Sandbox Code Playgroud)
在您的回答之后,我尝试了您提出的许多解决方案。为了检查编译器是否进入 for …