baoxin.zhou
BAN USER
Comments (5)
Reputation 60
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
1
of 1 vote
public static int f200(){
int i=1;
int ret=0;
while(i++<8){
ret+=f1();
ret<<1;
}
if(ret>=1 && ret <=200) {
return ret;
} else {
return f200();
}
}
Comment hidden because of low score. Click to expand.
0
of 0 vote
I don't think the return value is between 1 and 200 with equal probability.
- baoxin.zhou January 04, 2016Comment hidden because of low score. Click to expand.
5
of 5 vote
public static int random200() {
int a=f1();
int b=f1();
int c=f1();
int d=f1();
int e=f1();
int f=f1();
int g=f1();
int h=f1();
int r=a+b*2+c*4+d*8+e*16+f*32+g*64+h*128;
if(r<=200 && r>=1) {
return r;
} else {
return random200();
}
}
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
Java
- baoxin.zhou January 04, 2016