In my program I have a method calculateCost(), which gets the cost of a truck based on the minimum temperature of said truck.
public double calculateCost() {
int minimumTemperature = this.getTemperature();
System.out.println("Temp is: " + minimumTemperature);
double costOfTruck = 900 + 200 * (Math.pow(0.7, (minimumTemperature / 5)));
System.out.println("Cost is: " + costOfTruck);
return costOfTruck;
}
When this method is executed, the minimumTemperature correctly changes as shown in the console, however, the costOfTruck doesn't change when the minimumTemperature is changed.
如果minimumTemperature
<5,则由于整数除法, minimumTemperature / 5
将等于零,而Math.pow(0.7, (minimumTemperature / 5)
将等于1,因此请尝试使用双数值类型
double costOfTruck = 900 + 200 * (Math.pow(0.7, (minimumTemperature / 5.0)));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.