-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringFreq.java
More file actions
34 lines (25 loc) · 863 Bytes
/
StringFreq.java
File metadata and controls
34 lines (25 loc) · 863 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
28
29
30
31
32
33
34
package Collection;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class StringFreq{
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Your String");
String str = br.readLine();
System.out.println("Input String is " + str);
int tempA = 0;
int tempB = 0;
for (int i = 0; i < str.length(); i++) {
char ch = str.charAt(i);
if (ch == 'A') {
tempA++;
} else if (ch == 'I') {
tempB++;
}
}
System.out.println("Frequency of 'A': " + tempA);
System.out.println("Frequency of 'I': " + tempB);
System.out.println("The End");
}
}