为什么 Math.pow(x,y) 算作双精度值?
我正在编写一个Java程序来计算在My Singing Monsters中将怪物提升到一定水平需要多少食物。当我运行程序时,它说,“无法从double转换为int”。有人能解释一下为什么会这样吗?这是程序。
int totalFood = 0;
int level = 1;
int levelMeal = 5*(Math.pow(2,level-1));
int mealNumber = 1;
int levelGoal = 1;
while(level != levelGoal)
{
if(mealNumber != 5)
{
mealNumber += 1;
totalFood += levelMeal;
}
else if(mealNumber == 5)
{
mealNumber = 0;
level += 1;
}
}
if(level == levelGoal)
{
println("The total amount of food required for a monster to reach level " + levelGoal + " is " + totalFood + " food.");
}