java如何强制转换ifelse开关语句
我想我需要施展这个密码。我需要返回一个整数,但我必须乘以百分比,不希望它们被截断
我应该这样投吗brains = (double)brains - (this.getBrains() * 0.01);
我还应该在结尾处使用return语句吗?我在铸造方面很弱,我一直在努力寻找有帮助的例子,但它们没有帮助。
if(attacker >= attackee)
{
switch (weapon)
{
case 't':
brains = brains + (other.getBrains() * 0.01);
attack = other.getBrains() * -0.01;
other.addBrains(attack);
break;
case 's':
brains = brains + (other.getBrains() * 0.05);
attack = other.getBrains() * -0.05;
other.addBrains(attack);
break;
case 'c':
brains = brains + (other.getBrains() * 0.10);
attack = other.getBrains() * -0.10;
other.addBrains(attack);
break;
case 'k':
brains = brains + (other.getBrains() * 0.20);
attack = other.getBrains() * -0.20;
other.addBrains(attack);
break;
}
}
else
{
switch (weapon)
{
case 't':
brains = brains - (this.getBrains() * 0.01);
attack = this.getBrains() * 0.01;
other.addBrains(attack);
break;
case 's':
brains = brains - (this.getBrains() * 0.01);
attack = this.getBrains() * 0.01;
other.addBrains(attack);
break;
case 'c':
brains = brains - (this.getBrains() * 0.01);
attack = this.getBrains() * 0.01;
other.addBrains(attack);
break;
case 'k':
brains = brains - (this.getBrains() * 0.01);
attack = this.getBrains() * 0.01;
other.addBrains(attack);
break;
}
}
return attack;
}
共 (0) 个答案