go to previous page   go to home page   go to next page

Say that state is 1 and current is 'm'. Does the following evaluate to true or false?

      ( state==1 && current >= 'a' && current <= 'y')

Answer:

true


Ranges of Characters

The set of characters that Java uses are arranged in a sequence, called the collating sequence. Every character can be compared to any character. Character 'a' comes earlier in the sequence than 'z'.

This is useful if you wish to test for a range of characters. Here is part of the collating sequence for ASCII:

. . . 0123456789 . . . ABCDEFGHIJKLMNOPQRSTUVWXYZ . . . abcdefghijklmnopqrstuvwxyz . . .

There are non-alphabetic characters between the sequences '0' to '9', 'A' to 'Z', and 'a' to 'z'. It is good programming practice to test for ranges of characters only within one of these sequences.


QUESTION 9:

Does '1' < '5' evaluate to true or false?