-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRelFrequency.java
More file actions
50 lines (38 loc) · 844 Bytes
/
RelFrequency.java
File metadata and controls
50 lines (38 loc) · 844 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.util.Scanner;
public class RelFrequency
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
System.out.println("Enter the Text: ");
String text=input.nextLine();
char B[]=new char[text.length()];
double max=0;
int maxi=0;
for(int i=0;i<text.length();i++)
{
double count=1;
for(int j=i+1;j<text.length();j++)
{
if(text.charAt(i)==text.charAt(j))
{
count++;
B[j]='0';
}
else
continue;
}
if(B[i]!='0')
{
double rf=(count/text.length())*100;
System.out.println("The RF of "+text.charAt(i)+" :"+rf+"%");
if(rf>max)
{
max=rf;
maxi=i;
}
}
}
System.out.println(text.charAt(maxi)+" has the Maximum RF of :"+max+"%");
}
}