11.14 Write a script based on the program in Exercise 11.13 that inputs several
ID: 3763018 • Letter: 1
Question
11.14 Write a script based on the program in Exercise 11.13 that inputs several lines of text and uses String method indexOf to determine the total number of occurrences of each letter of the alphabet in the text. Uppercase and lowercase letters should be counted together. Store the totals for each letter in an array, and print the values in tabular format in an HTML5 textarea after the totals have been determined. Question 11.13 Write a script that inputs several lines of text and a search character and uses String method indexOf to determine the number of occurrences of the character in the text.
Explanation / Answer
SCRIPT
* We store the input string in an character array (below z) .(We want to create a character array z without any duplicate alphabet )
* We start traversing the string in array z[i].
for i=0 to i<z.length
Store the character at index i that is z[i] in temporary variable ch
for z[i+1] to z.length
if ch is equals to the any element of the rest of the array characters
then move the cursor to next index and reduce the length of the string by 1
set s[k]=s[k+1] // deleting the alphabet which is already in array z
set j=i
* Create a new array of integers to store the count of total number of appearances of alphabets in the string (below t)
* Compare every element of string s with the every element of character array z
if both are equal then
increase count by 1
Add the final count value to the array t (which is used to store the final count of total number of occurrences of the alphabet in the string )
* Print the count of the alphabet
CODE
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.