Java Not Greater than Or Equal to Operator for Char Type

So I’m trying to write this in a short way:

char letter;
while ( letter!='A' && letter!='B' && letter!= 'C... letter!= 'a' 
                                                     && letter !='b' && letter!=c)

Basically if the user does not input a letter between A and C, a while loop will run until A,B,C,a,b,c is inputted.

It should be in the form of

while(letter<'a' && letter > 'c')

but it didn’t work apparently because if I inputted F, is it greater than ‘C’, but it is less than ‘c’, since char uses ACSII.

Leave a Comment