Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem b Write a program that analyzes text written in the console by counting the number of times each of the 26 letters in the
Problem b Write a program that analyzes text written in the console by counting the number of times each of the 26 letters in the alphabet occurs. Uppercase and lowercase letters should be counted together (for example, both A' and 'a, should count as an A). Any characters that are not letters should be ignored. You must prompt the user to enter the text to be analyzed. Then, for any letter that appeared at least once in the text, print out the number of times it appeared (and do so in alphabetical order). An effective way to count characters is to read from the console string-by-string, and loop through all of the characters of each of these strings. Similar to Problem a, the hasNext() method of the scanner will be useful, and when testing in Eclipse, press enter and then, once on the empty line, press CTRL-D when you are done typing the text You must use an array to keep track of how many times each letter is seen in the text. The array should have 26 elements (one for each letter in the alphabet). Index o should be used to track the number of A's in the file, index 1 to track the B's, index 2 to track the C's, etc., up to index 25 for the Z's. You could use a massive if/else block, but the whole reason to use arrays is to make your programs easier. So, instead, think about how to convert each character you read into the correct index and then increment that value in the array. For example, if you read an A, then you should increment the value in index o. Specifically, you will need to determine if the character is an uppercase letter (between ?' and Z'), a lowercase letter (between a, and z'), or something else. If it is a letter, convert it into the appropriate index. Recall that characters and integers are interchangeable via the ASCII table conversion1. Consider this example to help get you started: char input :'z'; int indexinputa' 1 index equals 25, as 'z' is 122 and 'a' is 97
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started