Java Reference
In-Depth Information
} else {
// It is not less
than z
System.out.println(
"The code is greater than a but it's not a letter");
}
} else {
System.out.println(
"The code is less than a and it's not a
letter");
}
}
} else {
System.out.println("The code is less than A so it's not a
letter");
}
}
}
LetterCheck.java
How It Works
This program figures out whether the character stored in the variable symbol is an uppercase letter, a
lowercase letter, or some other character. The program first generates a random character with a numeric
code between 0 and 127, which corresponds to the characters in the basic 7-bit ASCII (ISO 646) charac-
ter set. The Unicode coding for the ASCII characters is numerically the same as the ASCII code values.
Within this character set, the letters A to Z are represented by a contiguous group of ASCII codes with
decimal values from 65 to 90. The lowercase letters are represented by another contiguous group with
ASCII code values that have decimal values from 97 to 122. So to convert any capital letter to a lower-
case letter, you just need to add 32 to the character code.
The if statements are a bit convoluted, so let's look at the diagram of the logic in Figure 3-3 .
FIGURE 3-3
 
 
Search WWH ::




Custom Search