Write a program in java to enter a string convert the string to uppercase and print the frequency of the characters present in the string.

 THE FOLLOWING PROGRAM SEGMENT SHOWS HOW TO CONVERT THE STRING IN UPPERCASE AND PRINT THE FREQUENCY OF THE CHARACTERS PRESENT IN THE STRING.

import java.util.*;

class frequency

{

    public static void main (String args[])

    {

        Scanner ob = new Scanner (System.in);

        System.out.println("Enter any STRING");

        String word = ob.nextLine();

        int l = word.length();

        word = word.toUpperCase();

        System.out.println("CHARACTERS \t FREQUENCY");

        char c;

        int count;

        

        for(c = 'A' ; c <= 'Z'; c++)

        {

            count = 0;

            for (int i = 0 ; i < l; i++)

            {

                if(word.charAt(i) == c)

                {

                    count++;

                }

                

                if(count > 0)

                {

                    System.out.println(c + "\t\t\t"+count);

                }

                }

            }

        }

    }

            

Hope you guys found it helpful.

Please share it with your friends and comment down in the comment section below.

Follow https://askrisfor.blogspot.com/ for more such updates.

Visit us again.

Thank you!!

Comments

Popular Posts