i got this seemingly simple task in computer class that has proven itself to be harder than i though: the program gets a random float between 0 - 1 that then i need to turn into an int between 0 - 17 not including 0 & 17 (sixteen possible values). so i started by making a simple for loop which didn't really work so i went and hard coded it:
public static float step(float input){
if(input < (1/16 * 1)){
return 1;
}else if(input < (1/16 * 2)){
return 2;
}else if(input < (1/16 * 3)){
return 3;
}else if(input < (1/16 * 4)){
return 4;
}else if(input < (1/16 * 5)){
return 5;
}else if(input < (1/16 * 6)){
return 6;
}else if(input < (1/16 * 7)){
return 7;
}else if(input < (1/16 * 8)){
return 8;
}else if(input < (1/16 * 9)){
return 9;
}else if(input < (1/16 * 10)){
return 10;
}else if(input < (1/16 * 11)){
return 11;
}else if(input < (1/16 * 12)){
return 12;
}else if(input < (1/16 * 13)){
return 13;
}else if(input < (1/16 * 14)){
return 14;
}else if(input < (1/16 * 15)){
return 15;
}else{
return 16;
}
}
but for some reason that i can just not find it returns always 16! could anyone help me? (JAVA please)
Hint #1: 1/16 is the integer zero.
Hint #2: If you multiply input by ?? and convert it to an integer, what do you get? ( No, you don't need a chain of if
statements .... )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With