Write a program that will read a line of text that ends with a period, which serves as a sentinel value. Display all the letters that occur in the text, one per line and in alphabetical order, along with the number of times each letter occurs in the text. Use an array of base type int of length 26, so that the element at index 0 contains the number of a’s, the element at index 1 contains the number of b’s, and so forth. Allow both uppercase and lowercase letters as input, but treat uppercase and lowercase versions of the same letter as being equal. Hints: Use one of the methods toUpperCase or toLowerCase in the wrapper class Character, described in Chapter 6. You will find it helpful to define a method that takes a character as an argument and returns an int value that is the correct index

This project is a bit challenging to get the loop conditions right. The objective is to keep the array index within bounds and count only letters. Another little problem is how to get the printable character code from the array index after the letter counts have been determined. The "trick" is to know that adding 65 decimal to the array index will produce the ASCII code for the character.

See the code in CountLettersInLine.java.

Computer Science & Information Technology

You might also like to view...

Which text-wrapping option will wrap text around the right and left side of a picture, wherever there happens to be room?

A) In front of text B) Tight C) In line with margins D) In line with text

Computer Science & Information Technology

A typical laptop computer has the following components except ________?

a. Integrated LCD display b. Integrated speakers c. USB ports d. 3.5-inch SATA

Computer Science & Information Technology