JAVA Write a method that computes how often each letter A-Z or a-z occurs in a string. Don't distinguish between upper- and lowercase letters. Return an array of length 26. The ith element contains the number of times that the letter 'a' + i or 'A' + i occurs in the string. The string may contain other characters that you should simply skip
JAVA
Write a method that computes how often each letter A-Z or a-z occurs in a string. Don't distinguish between upper- and lowercase letters. Return an array of length 26. The ith element contains the number of times that the letter 'a' + i or 'A' + i occurs in the string. The string may contain other characters that you should simply skip.
logic:-
Read string from user and store in variable .
store the length of string using length() method.
Pass string and its length to function .
function definition:-
set char c=' '
define linkedHashMap with character and integer mapping.
iterate for each character in string
if str.charAt(i) ranges between 'a ' and 'z' or str.charAt(i) ranges between 'A' and 'Z'
c=str.charAt(i)
obje.put(c,obj.getOrDefault(c,0)+1)
use forEach method to display (k,v) mapping.
Step by step
Solved in 3 steps with 1 images