Write a program that will read a line of text from the keyboard. Display all the
ID: 3622878 • Letter: W
Question
Write a program that will read a line of text from the keyboard. 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. Allow the user to repeat this task until the user says he or she want to quit the program.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: You might find it helpful to define a method that takes in a character as an argument and returns an int value that is the correct index for that character. For example, the argument ‘a’ results in 0 as the return value, the argument ‘b’ results in 1 as the return value, and so on. Note that you can use type cast, such as (int) letter, to change a char to an int. Of course, this will not get the number you want, but if you subtract (int) ‘a’, you will then get the right index.
Explanation / Answer
It seems that you need it in any language so...
let us use JAVA
you can take the character from a whole string by using
charAt() methid just like this
int []Array=new int[26];
String s=new String();
Scanner scan = new Scanner();
s=scan.next();
s.toLowerCase();
char c;
c=s.charAt();
switch(c){
case 'a':Array[0]++;break;
.....
.....
}
and so on
you can use a for loop instead of switch bu you should use the character as an integer using casting . And the condition is to insert an ending number such as -1 or any thing else....
you can use them in other method so you can call it while the user does not end out your program.
I hope this is enough. If you need more info just send me a message and I'll answer you.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.