Write a program where the user enters a word and it counts t
Solution
import java.util.Scanner;
public class Occurence {
 public static void main(String args[])
 {
 int count=0;
 System.out.println(\"Enter the String: \");
 Scanner sc = new Scanner(System.in);
 String s = sc.nextLine();
 for(char i=\'a\';i<=\'z\';i++)
 {
 for(int j=0;j<s.length();j++)
 {
 if(s.charAt(j)==i){
 count++;
 }
 }
 if(count!=0){
 System.out.println(i+\"=\"+count);
 count=0;
 }
 }
 }}
Output:- Enter the string:- abracadabra
a=5
b=2
c=1
d=1
r=2
Explanation:-
As, i loop is initializesd from \'a\' to \'z\' and j loop is initialised from 0 to length of string. charAt() method is used to extract the character at specified position. The next condition is used to check that character of string is amtched with i loop or not. If, it is then value of count is incremented and value of i and count is printed and again count is initialised to zero for next iteration.

