wanted to use a switch statement in Java, but the variable in the switch-statement (switch(variable)) should be compared to random numbers in the case-statements (case(randomNumber)). But I get an error message like that: "case expressions must be constant expressions". So does my case-statements doesn't work with random numbers? I thought that the error message means that i have to preface the variables with "final", but that didn't work either. So, are if ... else statements the only way? I hope I explained my problem well enough to understand. (I'm just beginning with java and the whole terminology that comes with coding)
int number = 6; //some number between 0-9
int randomNumber1 = ((int)(Math.random() * 10));
int randomNumber2 = ((int)(Math.random() * 10));
int randomNumber3 = ((int)(Math.random() * 10));
switch(number)
{
case(randomNumber1):
//some code here
case(randomNumber2):
//some code here
case(randomNumber3):
//some code here
default:
//some code here
}