mardi 9 octobre 2018

An if statement if it is within the range of another number

I'm messing around with if statements and I was wondering if there was a more efficient way of expressing TRUE if an int is within the range of another. e.g. true if c is within 5 of 20 (15-25 would work) I'm trying to avoid this:

int c = console.nextInt();
if (c <= 25 && c >= 15)

Aucun commentaire:

Enregistrer un commentaire