我正在制作2个生成的整数然后我将它们分开。我想检查2个除以整数的结果是整数还是小数。然后我将尝试比较结果并将结果与带有此代码的字符串交换,但它停止工作。
Random r = new Random();
int first = r.nextInt(50 - 1) + 1;
Random z = new Random();
int twond = z.nextInt(50 - 1) + 1;
float Resultas = (first / twond);
Result = (int) Resultas;
String floatResult = Float.toString(Resultas);
while (floatResult != String.valueOf(Result)) {
Random s = new Random();
first = s.nextInt(50 - 1) + 1;
Random y = new Random();
twond = y.nextInt(50 - 1) + 1;
Resultas = (first / twond);
Result = (int) Resultas;
floatResult = Float.toString(Resultas);
}
答案 0 :(得分:3)
if (first % twond == 0) {
// result is an integer
}