Professional Documents
Culture Documents
A.Y. 2023-24
ASSIGNMENT – 20
import java.util.*;
public class Frequency
{
public void findFrequency()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter a string: ");
String str = sc.nextLine();
str = str.toUpperCase();
int count = 0;
char ch1;
System.out.println("Char" + "\t" + "Frequency");
for(char ch = 'A'; ch <= 'Z'; ch++)
{
count = 0;
for(int j = 0; j < str.length() ; j++)
{
ch1 = str.charAt(j);
if(ch == ch1)
count++;
}
if(count != 0)
{
System.out.println(ch + "\t" + count);
}
}
}
public static void main(String [] args)
{
Frequency obj = new Frequency();
obj.findFrequency();
}
}
OUTPUT
Enter a string:
computer applications
Char Frequency
A 2
C 2
E 1
I 2
L 1
M 1
N 1
O 2
P 3
R 1
S 1
T 2
U 1
Variable Name Data type Description