我生成兩個隨機的int數(a和b)。如果(a%b)== 0,我想繼續,否則我想通過刷新來更改隨機數。我舉個例子的代碼:刷新隨機在一個if case
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和b)。如果(a%b)== 0,我想繼續,否則我想通過刷新來更改隨機數。我舉個例子的代碼:刷新隨機在一個if case
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;
}
// a and b are random and out of the loop which means (a%b)==0
// do something with a and b
這段代碼的目的是什麼? void m(){//如果(a%b!= 0)m(),則初始化一個& b;; //做某事' – 2013-04-28 19:42:30
你可以使用while循環,看我的回答 – Elior 2013-04-28 19:43:23
謝謝@Elior。你和Mike Young的答案是一樣的。它解決了我的問題。 – halilkaya 2013-04-28 19:50:52