30 likes | 107 Views
Character Frequency Distribution.
E N D
Character Frequency Distribution • Write a program that will read in a line of text and output a list of all the letters that occur in the text, along with the number of times each letter occurs. End the line with a period that serves as a sentinel value. The letters should be listed in alphabetical order when they are output.
Problem hints • Use an array of base type int of length 26, so that each indexed variable contains the count of how many letters there are. • Array indexed variable 0 contains the number of a’s, array indexed variable 1 contains the number of b’s, and so forth (please refer the figure below) # of b’s / B’s # of z’s / Z’s # of a’s / A’s freq: 0 1 2 24 25 • Allow both, uppercase and lowercase letters as input but treat both versions of the same letter as being equal
More hints • You will want to use one of the functions Character.toUpperCase or Character.toLowerCase in the wrapper class Character. • You will find it helpful to define a method that takes a character as an argument and return an int value that is the correct index for that character. • For example, for an input ‘a’, the method returns 0, for input ‘b’, the method returns 1, etc. • Note that you can use a type cast to change a char to an int, like (int)letter. Of course, this will not get the number you want, but if you subtract (int) ‘a’, you will then get the right index