-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlphabetsFrequency.java
More file actions
27 lines (25 loc) · 850 Bytes
/
Copy pathAlphabetsFrequency.java
File metadata and controls
27 lines (25 loc) · 850 Bytes
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
package basic;
import java.util.Scanner;
class AlphabetsFrequency {
public static void main(String[] args) {
Scanner ob = new Scanner(System.in);
System.out.print("Enter a string:");
String str = ob.nextLine();
str = str.toLowerCase();
System.out.println("===========================");
System.out.println("Alphabet \t Frequency");
System.out.println("===========================");
for (char ch = 'a'; ch <= 'z'; ch++) //Loop to count frequency of characters
{
int count = 0;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == ch) {
count++;
}
}
if (count != 0) {
System.out.println(" " + ch + "\t\t\t" + count);
}
}
}
}