forked from NischayKG/My_Java_Programs_of_Strings
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhighest_frequency_character.java
More file actions
36 lines (35 loc) · 903 Bytes
/
Copy pathhighest_frequency_character.java
File metadata and controls
36 lines (35 loc) · 903 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
35
36
//19. Program to Find Highest Frequency Character in a String.
import java.util.*;
class highest_frequency_character
{
public static void main(String arr[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string :");
char str[]=sc.next().toCharArray();
int fre[]=new int[26];
for(int i=0;i<26;i++)
{
fre[i]=0;
}
int indx=0;
for(int i=0;i<str.length;i++)
{
indx=str[i]-97;
fre[indx]++;
}
int max=-1;
int hold=0;
for(int i=0;i<26;i++)
{
if(max<fre[i])
{
max=fre[i];
hold=i;
}
}
hold=hold+97;
char ch=(char)(hold);
System.out.println("The Highest Frequency Character is : "+ch);
}
}