-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfrequency_of_each_character.java
More file actions
39 lines (38 loc) · 1.05 KB
/
frequency_of_each_character.java
File metadata and controls
39 lines (38 loc) · 1.05 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
//53.Program to Count the Number of Occurrence of each Character Ignoring the Case of Alphabets Display them
import java.util.*;
class frequency_of_each_character
{
public static void count_freq(String str)
{
int arr[]=new int[256];
for(int i=0;i<256;i++)
{
arr[i]=0;
}
char chr[]=str.toCharArray();
int l=chr.length;
for(int i=0;i<l;i++)
{
char ch=chr[i];
int n=(int)ch;
arr[n]++;
}
System.out.println("The character and it's frequency are :");
for(int i=0;i<256;i++)
{
if(arr[i]!=0)
{
int n=arr[i];
char ch=(char)i;
System.out.println(ch+" = "+n+ " times");
}
}
}
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter the String :");
String str=new String(sc.nextLine());
count_freq(str);
}
}