我生成两个随机的int数字(a和b)。如果(a%b)== 0我想继续,否则我想通过刷新来改变randoms。我给出了一个示例代码:
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.
}
答案 0 :(得分:1)
int a = //random;
int b = //random;
while((a%b)!=0) {
a = // random
b = // random
}
// do something
因此,当%b不等于0时,它将为a和b生成新的随机数 当while循环的条件为false时,它将停止生成,然后您可以恢复代码
答案 1 :(得分:1)
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