我生成两个随机整数(a 和 b)。如果 (a%b)==0 我想继续,否则我想通过刷新来改变随机数。我给出一个示例代码:
int a = //random;
int b = //random;
if ((a%b)==0) {
// do something
} else {
// I want to change a and b and do that if case again.
}
我生成两个随机整数(a 和 b)。如果 (a%b)==0 我想继续,否则我想通过刷新来改变随机数。我给出一个示例代码:
int a = //random;
int b = //random;
if ((a%b)==0) {
// do something
} else {
// I want to change a and b and do that if case again.
}
int a = //random;
int b = //random;
while((a%b)!=0) {
a = // random
b = // random
}
// do something
所以这样,当 a%b 不等于 0 时,它将为 a 和 b 生成新的随机数,当 while 循环的条件为假时,它将停止生成它,然后你可以恢复你的代码
int a= // random
int b= // random
while ((a%b)!=0)
{ a = // random;
b = // random;
}
// a and b are random and out of the loop which means (a%b)==0
// do something with a and b