-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmaximumcharacter.java
38 lines (36 loc) · 990 Bytes
/
maximumcharacter.java
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
import java.util.*;
public class maximumcharacter
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the string?");
String str=sc.nextLine();
str=str.toLowerCase();
char arr[]=new char[str.length()];
for(int i=0;i<str.length();i++)
{
arr[i]=str.charAt(i);
}
int max=0;char ch=' ';char g=' ';
for(int i=0;i<str.length();i++)
{
char chr=str.charAt(i);
int count=0;
for(int j=0;j<str.length();j++)
{
if(chr==arr[j])
{
count+=1;
// g=str.charAt(j);
}
}
if(count>max)
{
max=count;
ch=chr;
}
}
System.out.println("The character with maximum number of frequency is "+ch+" frequency is "+max);
}
}