1 / 3

Character Frequency Distribution

Character Frequency Distribution.

Download Presentation

Character Frequency Distribution

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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.

  2. 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

  3. 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

More Related