Can I make my switch statement check if a value is more or less than something else?

Can I make my switch statement check if a value is more or less than something else (see the example below)? As it is, it doesn’t work, unfortunately. I can make a sequence of if-else statements, but switch seems to be the obvious choice when you check the state of only one variable

public static String getGreeting(){
        double rd = Math.random();
        String greeting;
        switch(rd){
            case < 0.2:
                greeting = "Hello!";
                break;
            case < 0.4:
                greeting = "Hi there!";
                break;
            case < 0.6:
                greeting = "Nice to see you!";
                break;
            case < 0.8:
                greeting = "Greetings!";
                break;
            default:
                greeting = "Aloha!";
        }
        return greeting;
    }

Hi,
no, switch only deals with matching values.
What you could do is alter what you’re checking to make it work.
for example,

double rd = Math.Random() * 4;
int rdint = (int)rd;

would then give you 0,1,2 or 3, which you could use.

Hope that helps

1 Like

Thank you! Maybe, you have some other options in mind?