YOUR AD GOES HERE

Input a string and print the frequency of each alphabet?

Published 16, Nov 2026

Mr. Shiv


Description:
Input astring and print the frequency of each alphabet?
Solution :-

import java.util.Scanner;

public class stringprogram
{
public static void main( )
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a string: ");
String str = sc.nextLine();

str = str.toLowerCase();

int[] freq = new int[26];

for (int i = 0; i str.length(); i++)

{
char ch = str.charAt(i);

if (ch = 'a' && ch = 'z')

{
freq[ch - 'a']++;
}
}

for (int i = 0; i 26; i++)

{
if (freq[i] 0)
{
System.out.println((char)(i + 'a') + " = " + freq[i]);
}
}
}
Output :-
Enter a string: Mr Shiv

h = 1
i = 1
m = 1
r = 1
s = 1
v = 1

Releted More Videos

  • Sorry!!! Nothing to show

You May Also Like

YOUR AD GOES HERE

YOUR AD GOES HERE