-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmailCharFrequency.java
More file actions
48 lines (37 loc) · 1.29 KB
/
EmailCharFrequency.java
File metadata and controls
48 lines (37 loc) · 1.29 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import java.util.Scanner;
public class EmailCharFrequency {
public static void findFrequencies(String email) {
char[] chars = new char[email.length()];
int[] freq = new int[email.length()];
int uniqueCount = 0;
for (int i = 0; i < email.length(); i++) {
char ch = email.charAt(i);
if (!Character.isLetter(ch)) {
boolean found = false;
for (int j = 0; j < uniqueCount; j++) {
if (chars[j] == ch) {
freq[j]++;
found = true;
break;
}
}
if (!found) {
chars[uniqueCount] = ch;
freq[uniqueCount] = 1;
uniqueCount++;
}
}
}
System.out.println("Frequencies of numeric and special characters:");
for (int i = 0; i < uniqueCount; i++) {
System.out.println(chars[i] + " --> " + freq[i]);
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter an email ID: ");
String email = scanner.nextLine();
findFrequencies(email);
scanner.close();
}
}