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

String Methods in Java for ICSE Class 10: 25 Output Questions with Answers
ICSE Class 10 Computer Applications practice on String class methods: length, charAt, indexOf, lastIndexOf, substring, replace, trim, compareTo, equals and more, with 25 board-style output questions and step-by-step answers.

Special Number Programs in Java for ICSE: Armstrong, Spy, Neon, Disarium, Pronic and More
Every special number asked in ICSE Computer Applications – prime, perfect, Armstrong, palindrome, automorphic, neon, spy, Niven, duck, buzz, Disarium, special and pronic numbers – with definitions, examples and one complete Java program that checks them all.

Math Library Methods in Java for ICSE Class 9 (with Outputs)
ICSE Class 9 Computer Applications notes on the Java Math class: sqrt, cbrt, pow, abs, max, min, ceil, floor, round, rint and random, with return types, tricky negative-number outputs and Java expressions for formulas.