Frequency of letters
Write a program to accept a string and print the frequency of letters in the given format.
Write a program to accept a string and print the frequency of letters in the given format.
I/p I love my India
O/p
Frequency of characters in the string
A 1
D 1
E 1
I 3
L 1
M 1
N 1
O 1
V 1
Y 1
import java.util.*;
class Frequency_of_characters{
public static void main(){
Scanner ob=new Scanner(System.in);
System.out.println("Enter a String");
String str=ob.nextLine();
str=str.toUpperCase();
System.out.println("Frequency of characters in the string \n");
int l=str.length();
int f=0;
for(int i=65;i<=90;i++){
char ch=(char)i;
for(int j=0;j<l;j++){
if(str.charAt(j)==ch){
f++;
}
}
if(f!=0){
System.out.println(ch+" \t"+f);
}
f=0;
}
}
}Related Posts
Continue learning with these related articles
Sum of First n Natural Numbers in Java (Loop and Formula)
Find the sum of the first n natural numbers in Java with a for loop, a while loop and the formula n(n + 1)/2, with a dry run and the sums of even numbers, odd numbers, squares and cubes.
Prime Number Program in Java: Check a Number and Print Primes in a Range
Check whether a number is prime in Java by counting its factors, a faster square-root method with isPrime(), and a program that prints all prime numbers in a range.

Encapsulation, Access Specifiers and Scope of Variables in Java for ICSE Class 10
ICSE Class 10 Computer Applications notes on encapsulation: private, default, protected and public access, data hiding with getter and setter methods, instance vs static (class) variables, local variables and scope, with a solved BankAccount program.