JAVA
java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class LetterFrequency
{
/* Count the number of occurrences of each letter in a string */
public static void main(String[] args)
{
// a sample text
String text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua";
text = text.toLowerCase();
int l = text.length();
char ch;
int count = 0;
for(char i='a'; i<='z'; i++)
{
count = 0;
for(int j = 0; j < l; j++)
{
ch = text.charAt(j);
if(ch == i)
count++;
}
if(count != 0)
{
System.out.println(i + ": " + count);
}
}
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Ejecutar