dimanche 20 octobre 2019

Is there a convenient way to make long if statements in Java? [duplicate]

Is there a convenient way to make long if statements readable?

for example=

if ( x == 9 || x == 20 || x == 39 || x == 45 ){
   // Do this
}

or in my case, even more random variables that you cant do something like this with:

if (  1 < x < 20 ){
    // Do this
}

is there any way to do something like this:

if ( x == (9, 20, 39, 45) ){
    // Do this
}

Aucun commentaire:

Enregistrer un commentaire