Here accept a string from the user by the method nextLine(). which is found under the Scanner class of java.util package. now extract each character from it. if the character is alphabetic then increment the corresponding counter. Now print those counters one after another. The details
import java.util.*;
class FrequencyChar
{
public static void main(String []args)
{
String str;
int []arr=new int[26];
Scanner sc=new Scanner(System.in);
System.out.print("Enter Your Text Here : ");
str=sc.nextLine();
str=str.toUpperCase();
char ch;
for(int i=0;i<str.length();i++)
{
ch=str.charAt(i);
if(ch>=65 && ch<=90)
arr[ch-65]++;
}
for(int j=0;j<26;j++)
{
if(arr[j]>0)
System.out.println(((char)(j+65)) + " : " + arr[j]);
}
}
}
Here we take an integer array of length 26. Indexes of this array represent the character A-Z. That is Index 0 is represent A, Index 1 represents B, Index 2 represents C …… and so on.