import java.util.Random;
public class dice
{
private int times;
private int roll;
private int side;
Random roller = new Random();
public void setTimes(int sides)
{
times = sides;
}
public void setSides(int die)
{
side = die;
}
public int getRoll()
{
int total; //here it is
int c = 0;
while (c <= times)
{
c = c + 1;
int rol = 0;
roll = roller.nextInt(side) + 1;
rol = rol + roll;
total = rol; //here it is initialized
}
return total; //here it says variable not initialized
}
}
while 循环内部不保证执行 - 例如,如果times
由于编程错误而小于零。编译器知道这一点,因此在确定是否total
已初始化。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)