Java Reference
In-Depth Information
LISTING 8.3
continued
OUTPUT
Enter a sentence:
In Casablanca, Humphrey Bogart never says "Play it again, Sam."
A: 0 a: 10
B: 1 b: 1
C: 1 c: 1
D: 0 d: 0
E: 0 e: 3
F: 0 f: 0
G: 0 g: 2
H: 1 h: 1
I: 1 i: 2
J: 0 j: 0
K: 0 k: 0
L: 0 l: 2
M: 0 m: 2
N: 0 n: 4
O: 0 o: 1
P: 1 p: 1
Q: 0 q: 0
R: 0 r: 3
S: 1 s: 3
T: 0 t: 2
U: 0 u: 1
V: 0 v: 1
W: 0 w: 0
X: 0 x: 0
Y: 0 y: 3
Z: 0 z: 0
Non-alphabetic characters: 14
Both of the counter arrays are indexed from 0 to 25. We have to map each
character to a counter. A logical way to do this is to use upper[0] to count the
number of 'A' characters found, upper[1] to count the number of 'B' characters
found, and so on. Likewise, lower[0] is used to count 'a' characters, lower[1] is
VideoNote
Discussion of the
LetterCount example.
Search WWH ::




Custom Search