我正在尝试创建一个应用程序,通过使用开关盒生成随机操作数问题。
MaxDigit = Difficulty.Level;
Random RandomNumber = new Random();
//Set the First and Second Number to Random Number
FNumber = RandomNumber.nextInt(MaxDigit);
SNumber = RandomNumber.nextInt(MaxDigit);
Random OperandsChoise = new Random();
int Operands = OperandsChoise.nextInt(4);
if ((FNumber / SNumber) >= 1) {
switch (Operands){
case 0 :
this.Answer = this.FNumber + this.SNumber;
this.QTyoe = FNumber + "+" + SNumber + "=";
break;
case 1 :
this.Answer = this.FNumber - this.SNumber;
this.QTyoe = FNumber + "-" + SNumber + "=";
break;
case 2 :
this.Answer = this.FNumber * this.SNumber;
this.QTyoe = FNumber + "*" + SNumber + "=";
break;
case 3 :
this.Answer = (this.FNumber +2) / (this.SNumber +1);
this.QTyoe = FNumber + "/" + SNumber + "=";
break;
}
}
maxdigit从另一个名为“难度”的活动中获取整数,让用户决定他们想挑战的数学问题的难度(easy-9、medium-99、hard-999)。但不知何故,盗贼一直得到0,并兑现崩溃。
有没有办法将snumber设置在范围内,并使答案不小于1?
1条答案
按热度按时间vfh0ocws1#
我从你的代码中看到
FNumber
及SNumber
永远都是积极的。可以将第二个数字钳制为永远不小于0,例如:上面的代码片段将确保
SNumber
永远不会超过MaxDigit
但始终大于或等于1。